import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//实现侦听器接口
class Deng implements ActionListener{
public JFrame jf = new JFrame("酒店管理系统");
public Container con = jf.getContentPane();
public Toolkit toolkit = Toolkit.getDefaultToolkit();
public Dimension sc = toolkit.getScreenSize();
public JLabel name1 = new JLabel("用户名");
public JLabel pass1 = new JLabel("密码");
public JTextField textName = new JTextField();
public JPasswordField textPs = new JPasswordField();
public JButton button1 = new JButton("登陆");
public JButton button2 = new JButton("重置");
public Deng() throws Exception{
con.setLayout(null);
jf.setSize(sc.width / 3, sc.height * 10 / 25);
jf.setLocation(sc.width / 3, sc.height / 4);
con.setLayout(null);
jf.setSize(sc.width / 3, sc.height * 10 / 25);
jf.setLocation(sc.width / 3, sc.height / 4);
jf.setResizable(false);
name1.setLocation(80, 30);
name1.setSize(100, 100);
name1.setForeground(Color.white);
pass1.setLocation(80, 90);
pass1.setSize(100, 100);
pass1.setForeground(Color.white);
textName.setSize(140, 20);
textName.setLocation(170, 70);
textPs.setSize(140, 20);
textPs.setLocation(170, 130);
textPs.setEchoChar('*');
button1.setSize(90, 25);
button1.setLocation(80, 180);
button2.setSize(90, 25);
button2.setLocation(220, 180);
//添加指定的动作侦听器,以接收发自此按钮的动作事件
button1.addActionListener(this);
button2.addActionListener(this);
con.add(name1);
con.add(pass1);
con.add(textName);
con.add(textPs);
con.add(button1);
con.add(button2);
con.setBackground(Color.black);
//系统默认外观
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
jf.setResizable(false);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//处理动作事件
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
if(obj==button1){
JOptionPane.showMessageDialog(jf, "欢迎光临,请问你是要住店呢,还是要吃饭啊?");
}
if(obj==button2){
JOptionPane.showMessageDialog(jf, "很抱歉, 我们暂时未提供重置服务");
}
}
}
public class Denglu {
public static void main(String args[]) throws Exception{
new Deng();
}
}