2017/11/14
2017-11-16 09:31 1704班1组博客 阅读(218) 评论(0) 收藏 举报我们完成了测试代码的编写,明确了程序需求
测试代码如下:
package loginin;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class login {
private static JTextField jtf;
private static JPasswordField jpf;
private static JButton jb;
private static JLabel jl1,jl2,rs;
public static void main(String[] args) {
JFrame jf = new JFrame("登录界面");
jf.setSize(400, 300);
jf.setLayout(new FlowLayout(0,50,10));
jl1 = new JLabel("username");
jtf = new JTextField(10);
jl1.setPreferredSize(new Dimension(100,50));
jtf.setSize(200,100);
jl2 = new JLabel("password");
jpf = new JPasswordField(10);
jl2.setPreferredSize(new Dimension(100,50));
jpf.setSize(200,100);
jb = new JButton("login");
jb.setSize(200,100);
rs = new JLabel();
rs.setForeground(Color.red);
jf.add(jl1);
jf.add(jtf);
jf.add(jl2);
jf.add(jpf);
jf.add(jb);
jf.add(rs);
jf.setVisible(true);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String un = jtf.getText();
String pw = new String(jpf.getPassword());
if(un.equals("edmond")&&pw.equals("123")) {
rs.setText("login success!!");
} else {
rs.setText("username or password is wrong!!");
}
}
});
}
}
浙公网安备 33010602011771号