以下为两个类
//文本框,密码框,按钮,标签
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.test.kaoshi.conntest;
public class CM extends JFrame {
public CM() {
this.setTitle("古少毅.Java");
this.setBounds(200, 200, 200, 200);
final JTextField jf1 = new JTextField(10);
final JPasswordField jf2 = new JPasswordField(10);
JButton jb1 = new JButton("确定");
JButton jb2 = new JButton("重置");
JLabel lb1 = new JLabel(" 帐户名");
JLabel lb2 = new JLabel(" 密码");
setLayout(new FlowLayout());
add(lb1);
add(jf1);
add(lb2);
add(jf2);
add(jb1);
add(jb2);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jf1.setText(null);
jf2.setText(null);
}
});
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new CM();
}
}
//10以内的随机数
public class 随机数 {
public static void main(String[] args) {
double a = Math.random() * 10;
a = Math.ceil(a);
int randomNum = new Double(a).intValue();
switch (randomNum) {
case 1:
System.out.println(randomNum+"是随机出来的");
break;
case 2:
System.out.println(randomNum+"是随机出来的");
break;
case 3:
System.out.println(randomNum+"是随机出来的");
break;
case 4:
System.out.println(randomNum+"是随机出来的");
break;
case 5:
System.out.println(randomNum+"是随机出来的");
break;
case 6:
System.out.println(randomNum+"是随机出来的");
break;
case 7:
System.out.println(randomNum+"是随机出来的");
break;
case 8:
System.out.println(randomNum+"是随机出来的");
break;
case 9:
System.out.println(randomNum+"是随机出来的");
break;
case 10:
System.out.println(randomNum+"是随机出来的");
break;
}
}
}
温馨提示:答案为网友推荐,仅供参考