- 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.JTextField;
- public class action implements ActionListener {
- public static void main(String[] args) {
- action app = new action();
- }
- public void actionPerformed(ActionEvent e) {
- }
- private JFrame fm;
- private JTextField tf1, tf2;
- private JButton btn1;
- private JLabel lb1, lb2;
- action() {
- fm = new JFrame("My first Swing Example");
- tf1 = new JTextField();
- tf2 = new JTextField();
- lb1 = new JLabel("User");
- lb2 = new JLabel("Password");
- btn1 = new JButton("login");
- tf1.setBounds(100, 24, 225, 25);
- tf1.addActionListener(this);
- tf2.setBounds(100, 68, 225, 25);
- tf2.addActionListener(this);
- lb1.setBounds(10, 20, 60, 30);
- lb2.setBounds(10, 60, 60, 40);
- btn1.setBounds(10, 135, 92, 25);
- btn1.addActionListener(this);
- fm.setBounds(100, 100, 450, 250);
- 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(btn1);
- }
- }
複製代碼 |