-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventByAnonInner.java
More file actions
40 lines (35 loc) · 949 Bytes
/
EventByAnonInner.java
File metadata and controls
40 lines (35 loc) · 949 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
31
32
33
34
35
36
37
38
39
40
import java.awt.event.*;
import javax.swing.*;
public class EventByAnonInner extends JFrame
{
public EventByAnonInner()
{
// create basic panel
JPanel panel = new JPanel();
panel.setLayout( null );
// create example button
// events are handled via an anonymous inner class
JButton closeButton = new JButton( "Close" );
closeButton.setBounds( 40, 50, 80, 25 );
closeButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
System.exit( 0 );
}
});
// add components to frame
panel.add( closeButton );
add( panel );
// set frame attributes
setTitle( "Example" );
setSize( 300, 200 );
setLocationRelativeTo( null );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public static void main( String[] args )
{
EventByAnonInner ex = new EventByAnonInner();
ex.setVisible( true );
}
}