您的位置:首页 > 编程语言 > Java开发

11csdn-java周末作业(登陆界面)

2012-05-06 21:32 671 查看
import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Login implements ActionListener{

Frame frame;

TextField txtName;

TextField Password;

public Login(){

frame=new Frame();

frame.setTitle("登陆界面");

Panel p1,p2,p3,p4;

Label label1=new Label("请输入你的用户信息:");

Label label2=new Label("用户名:");

txtName=new TextField(10);

Label label3=new Label("密 码:");

Password=new TextField(10);

Button button1=new Button("确定");

Button button2=new Button("重置");

p1=new Panel();

p2=new Panel();

p3=new Panel();

p4=new Panel();

frame.add(label1,"North");

p1.setLayout(new BorderLayout());

p2.setLayout(new GridLayout(2,1));

p2.add(label2);

p2.add(label3);

p3.setLayout(new GridLayout(2,1));

p3.add(txtName);

p3.add(Password);

p1.add(p2, "West");

p1.add(p3, "Center");

txtName.addActionListener(this);

Password.addActionListener(this);

p4.add(button1);

p4.add(button2);

button1.addActionListener(this);

button2.addActionListener(this);

frame.add(p1,"Center");

frame.add(p4,"South");

frame.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

frame.setSize(220, 130);

frame.setLocation(300, 200);

frame.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

String str=e.getActionCommand();

if(str.equals("确定")){

submit();

}else{

clear();

}

}

private void clear() {

txtName.setText("");

Password.setText("");

}

private void submit() {

JOptionPane.showMessageDialog(frame,"登陆成功");

}

public static void main(String[] args) {

new Login();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐