- package loginSYSTEM;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class main implements ActionListener{
- public static void main(String[] args) {
-
- main app = new main();
-
- }
- @Override
- public void actionPerformed(ActionEvent e) {
-
- if(e.getSource()==btn1)
- {
- JOptionPane.showMessageDialog(null, "登入成功", "系統", JOptionPane.INFORMATION_MESSAGE );
- lb1.setText("[系統]您已登入,祝您使用愉快");
- tf1.setText("WELCOME USERS");
- tf2.setText("***********");
- }
- if(e.getSource()==btn2)
- {
- JOptionPane.showMessageDialog(null, "很抱歉,目前不開放新用戶註冊", "系統", JOptionPane.ERROR_MESSAGE );
- lb1.setText("[公告]請先登入,新用戶請先註冊");
- }
- }
- private JFrame fm;
- private JLabel lb1, lb2, lb3;
- private JButton btn1, btn2;
- private JTextField tf1, tf2;
-
- main()
- {
- fm = new JFrame("登入系統");
-
- tf1=new JTextField();
- tf2=new JTextField();
- lb1=new JLabel("[公告]請先登入,新用戶請先註冊",JLabel.CENTER);
- lb2=new JLabel("帳號:");
- lb3=new JLabel("密碼:");
- btn1=new JButton("登入");
- btn2=new JButton("註冊");
-
- tf1.setBounds(70, 45, 160, 30);
- tf1.addActionListener(this);
- tf2.setBounds(70, 82, 160, 30);
- tf2.addActionListener(this);
-
- lb1.setBounds(0, 10, 240, 30);
- lb2.setBounds(10, 40, 60, 40);
- lb3.setBounds(10, 77, 60, 40);
-
- btn1.setBounds(30, 135, 92, 25);
- btn1.addActionListener(this);
- btn2.setBounds(150, 135, 92, 25);
- btn2.addActionListener(this);
-
- fm.setBounds(100, 100, 300, 220);
- fm.setVisible(true);
- fm.setResizable(true);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.setLayout(null);
- fm.add(tf1);
- fm.add(tf2);
- fm.add(lb1);
- fm.add(lb2);
- fm.add(lb3);
- fm.add(btn1);
- fm.add(btn2);
- }
-
- }
複製代碼 |