1 public class InnerClass {
2 public static void main(String[] args) {
3
4 // 窗口
5 JFrame win = new JFrame("登陆界面");
6 // 桌布
7 JPanel jPanel = new JPanel();
8 win.add(jPanel);
9 // 按钮
10 JButton button = new JButton("登录");
11
12 // 匿名内部类的使用 1
13 // button.addActionListener(new ActionListener(){
14 // @Override
15 // public void actionPerformed(ActionEvent e) {
16 // JOptionPane.showMessageDialog(win, "点我点我!!!");
17 // }
18 // });
19 // 同上 匿名内部类的使用 2
20 button.addActionListener(e -> JOptionPane.showMessageDialog(win, "爱我你就抱抱我!!!"));
21
22 // 将按钮添加到界面
23 jPanel.add(button);
24
25 win.setSize(300 , 300);
26 win.setVisible(true);
27 win.setLocationRelativeTo(null);
28
29 }
30 }