急,求助高手,有几个Java的作业,请高手帮忙写写,谢谢
急,求助高手,有几个Java的作业,请高手帮忙写写,谢谢1。请设计一个Applet程序,其功能是:在窗口中摆放一个按钮,当不断地单击按钮时就显示它被单机的次数。2。请设计...
急,求助高手,有几个Java的作业,请高手帮忙写写,谢谢
1。请设计一个Applet程序,其功能是:在窗口中摆放一个按钮,当不断地单击按钮时就显示它被单机的次数。
2。请设计一个Applet程序,在上边分别添加两个标签,内容分别是“用户名”和“口令”,添加两个文本框,用来接收用户名和口令。添加一个文本区组件,输入口令时用*屏蔽其内容,当在口令框和用户名框内按回车时在文本区显示输入的内容。
3。从键盘中输入10哥整数,并将它们都储存在数组中。在数组中查找到最小的整数和它在数组中的下标,然后将它和数组中最前面的元素对换,然后输出数组中元素。 展开
1。请设计一个Applet程序,其功能是:在窗口中摆放一个按钮,当不断地单击按钮时就显示它被单机的次数。
2。请设计一个Applet程序,在上边分别添加两个标签,内容分别是“用户名”和“口令”,添加两个文本框,用来接收用户名和口令。添加一个文本区组件,输入口令时用*屏蔽其内容,当在口令框和用户名框内按回车时在文本区显示输入的内容。
3。从键盘中输入10哥整数,并将它们都储存在数组中。在数组中查找到最小的整数和它在数组中的下标,然后将它和数组中最前面的元素对换,然后输出数组中元素。 展开
2个回答
2010-12-19
展开全部
第一题:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class exec1 extends Applet {
int count = 0;
Label lblCount = new Label();
Button btnClick = new Button("点击");
public void init() {
lblCount.setText(String.valueOf(count++));
btnClick.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
lblCount.setText(String.valueOf(count++));
}
});
this.add(lblCount);
this.add(btnClick);
}
}
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "exec1.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>
第二题:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class exec2 extends Applet {
TextField txtName;
TextField txtPssw;
TextArea txaCone;
public void init() {
Label lblName = new Label("用户名");
txtName = new TextField();
txtName.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
txaCone.setText(txtName.getText() + "\n" + txtPssw.getText());
}
}
});
txtName.setColumns(20);
Label lblPssw = new Label("密码");
txtPssw = new TextField();
txtPssw.setEchoChar('*');
txtPssw.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
txaCone.setText(txtName.getText() + "\n" + txtPssw.getText());
}
}
});
txtPssw.setColumns(20);
txaCone = new TextArea();
Panel top = new Panel(new GridLayout(2, 2));
top.add(lblName);
top.add(txtName);
top.add(lblPssw);
top.add(txtPssw);
add(top, BorderLayout.NORTH);
add(txaCone, BorderLayout.CENTER);
}
}
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "exec2.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>
第三题:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class exec3 {
/**
* @param args
*/
public static void main(String[] args) {
int count = 0;
int arr[] = new int[10];
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入10个数字:输完一个换行");
try {
while (count < 10) {
String str = in.readLine();
arr[count] = str.trim().equals("") ? 0 : Integer.parseInt(str);
count++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int min = arr[0];
int pos = 0;
for (int i = 0; i < 10; i++) {
if (min > arr[i]) {
min = arr[i];
pos = i;
}
}
int temp = arr[0];
arr[0] = min;
arr[pos] = temp;
for (int i = 0; i < 10; i++) {
System.out.println(arr[i]);
}
}
}
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class exec1 extends Applet {
int count = 0;
Label lblCount = new Label();
Button btnClick = new Button("点击");
public void init() {
lblCount.setText(String.valueOf(count++));
btnClick.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
lblCount.setText(String.valueOf(count++));
}
});
this.add(lblCount);
this.add(btnClick);
}
}
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "exec1.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>
第二题:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class exec2 extends Applet {
TextField txtName;
TextField txtPssw;
TextArea txaCone;
public void init() {
Label lblName = new Label("用户名");
txtName = new TextField();
txtName.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
txaCone.setText(txtName.getText() + "\n" + txtPssw.getText());
}
}
});
txtName.setColumns(20);
Label lblPssw = new Label("密码");
txtPssw = new TextField();
txtPssw.setEchoChar('*');
txtPssw.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
txaCone.setText(txtName.getText() + "\n" + txtPssw.getText());
}
}
});
txtPssw.setColumns(20);
txaCone = new TextArea();
Panel top = new Panel(new GridLayout(2, 2));
top.add(lblName);
top.add(txtName);
top.add(lblPssw);
top.add(txtPssw);
add(top, BorderLayout.NORTH);
add(txaCone, BorderLayout.CENTER);
}
}
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "exec2.class"
width = "500"
height = "300"
>
</applet>
</center>
</body>
</html>
第三题:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class exec3 {
/**
* @param args
*/
public static void main(String[] args) {
int count = 0;
int arr[] = new int[10];
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入10个数字:输完一个换行");
try {
while (count < 10) {
String str = in.readLine();
arr[count] = str.trim().equals("") ? 0 : Integer.parseInt(str);
count++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int min = arr[0];
int pos = 0;
for (int i = 0; i < 10; i++) {
if (min > arr[i]) {
min = arr[i];
pos = i;
}
}
int temp = arr[0];
arr[0] = min;
arr[pos] = temp;
for (int i = 0; i < 10; i++) {
System.out.println(arr[i]);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询