返回列表 發帖
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;

  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JTextField;

  7. public class action implements ActionListener {
  8.         public static void main(String[] args) {
  9.                 action app = new action();
  10.         }

  11.         public void actionPerformed(ActionEvent e) {

  12.         }

  13.         private JFrame fm;
  14.         private JTextField tf1, tf2;
  15.         private JButton btn1;
  16.         private JLabel lb1, lb2;

  17.         action() {
  18.                 fm = new JFrame("My first Swing Example");
  19.                 tf1 = new JTextField();
  20.                 tf2 = new JTextField();
  21.                 lb1 = new JLabel("User");
  22.                 lb2 = new JLabel("Password");
  23.                 btn1 = new JButton("login");

  24.                 tf1.setBounds(100, 24, 225, 25);
  25.                 tf1.addActionListener(this);
  26.                 tf2.setBounds(100, 68, 225, 25);
  27.                 tf2.addActionListener(this);

  28.                 lb1.setBounds(10, 20, 60, 30);
  29.                 lb2.setBounds(10, 60, 60, 40);

  30.                 btn1.setBounds(10, 135, 92, 25);
  31.                 btn1.addActionListener(this);

  32.                 fm.setBounds(100, 100, 450, 250);
  33.                 fm.setVisible(true);
  34.                 fm.setResizable(true);
  35.                 fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  36.                 fm.setLayout(null);
  37.                 fm.add(tf1);
  38.                 fm.add(tf2);
  39.                 fm.add(lb1);
  40.                 fm.add(lb2);
  41.                 fm.add(btn1);
  42.         }
  43. }
複製代碼

TOP

返回列表