-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwingTest.java
More file actions
30 lines (24 loc) · 781 Bytes
/
SwingTest.java
File metadata and controls
30 lines (24 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package test;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SwingTest {
public static void main(String[] args) {
JFrame jframe = new JFrame("A Frame");
JButton jButton = new JButton("A Button");
//原来的写法
jButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Pressed");
}
});
//λ 写法
jButton.addActionListener(e -> System.out.println("Pressed"));
jframe.add(jButton);
jframe.pack();
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
System.out.println("");
}
}