JAVA第二次作业

源代码:

package hjhjh;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class LoginWindow extends JFrame implements ActionListener,ItemListener
{
JLabel user=new JLabel("用 户 名:");
JLabel password=new JLabel("密 码:");
JLabel usertype=new JLabel("用户类型:");
JButton login=new JButton("登陆");
JButton cancel=new JButton("取消");
ButtonGroup buttongroup=new ButtonGroup();
JRadioButton manager=new JRadioButton("管理员");
JRadioButton normaluser=new JRadioButton("普通用户");
JTextField text1=new JTextField(18);
JPasswordField text2=new JPasswordField(18);
public LoginWindow()
{
super("登陆窗口");
setSize(300,200);
setVisible(true);
setResizable(false);
setLayout(new FlowLayout(FlowLayout.CENTER,15,10));
add(user);
add(text1);
add(password);
add(text2);
add(usertype);
add(manager);
add(normaluser);
buttongroup.add(manager);
buttongroup.add(normaluser);
add(login);
add(cancel);
manager.addItemListener(this);
normaluser.addItemListener(this);
login.addActionListener(this);
cancel.addActionListener(this);
Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screen.width-300)/2,(screen.height-220)/2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==login)
{
;
}
else if(e.getSource()==cancel)
{
dispose();
System.exit(0);
}
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==manager)
{
;
}
else if(e.getSource()==normaluser)
{
;
}
}
public static void main(String args[])
{
new LoginWindow();
}
}

  

posted @ 2016-03-21 22:27  14软三吕凯瀚  阅读(134)  评论(0编辑  收藏  举报