-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path13.26.java.java
56 lines (41 loc) · 1.1 KB
/
13.26.java.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame implements ActionListener {
private JButton buttons[];
private final String names[] =
{ "one", "two", "three", "four", "five", "six" };
private boolean toggle = true;
private Container container;
private GridLayout grid1, grid2;
public Main()
{
super( "GridLayout Demo" );
grid1 = new GridLayout( 2, 3, 5, 5 );
grid2 = new GridLayout( 3, 2 );
container = getContentPane();
container.setLayout( grid1 );
buttons = new JButton[ names.length ];
for ( int count = 0; count < names.length; count++ ) {
buttons[ count ] = new JButton( names[ count ] );
buttons[ count ].addActionListener( this );
container.add( buttons[ count ] );
}
setSize( 300, 150 );
setVisible( true );
}
public void main( ActionEvent event )
{
if ( toggle )
container.setLayout( grid2 );
else
container.setLayout( grid1 );
toggle = !toggle;
container.validate();
}
public static void main( String args[] )
{
Main application = new Main();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}