-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEjercicio 14.15.java
66 lines (60 loc) · 2.56 KB
/
Ejercicio 14.15.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
57
58
59
60
61
62
63
64
65
66
// Fig. 14.15: BoxLayoutDemo.java
// Demonstrating BoxLayout.
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
publicclassBoxLayoutDemo extendsJFrame {
// set up GUI
publicBoxLayoutDemo()
{
super( "Demostrating BoxLayout");
// create Box containers with BoxLayout15
Box horizontal1 = Box.createHorizontalBox();
Box vertical1 = Box.createVerticalBox();
Box horizontal2 = Box.createHorizontalBox();
Box vertical2 = Box.createVerticalBox();
finalintSIZE= 3; // number of buttons on each Box
// add buttons to Box horizontal1
for( intcount = 0; count < SIZE; count++ )
horizontal1.add( newJButton( "Button "+ count ) )
// create strut and add buttons to Box vertical1
for( intcount = 0; count < SIZE; count++ ) {
vertical1.add( Box.createVerticalStrut( 25) );
vertical1.add( newJButton( "Button "+ count ) );
}
// create horizontal glue and add buttons to Box horizontal2
for( intcount = 0; count < SIZE; count++ ) {
horizontal2.add( Box.createHorizontalGlue() );
horizontal2.add( newJButton( "Button "+ count ) );
}
// create rigid area and add buttons to Box vertical2
for( intcount = 0; count < SIZE; count++ ) {
vertical2.add( Box.createRigidArea( newDimension( 12, 8) ) );
vertical2.add( newJButton( "Button "+ count ) );
}
// create vertical glue and add buttons to panel
JPanel panel = newJPanel();
panel.setLayout( newBoxLayout( panel, BoxLayout.Y_AXIS) );
for( intcount = 0; count < SIZE; count++ ) {
panel.add( Box.createGlue() );
panel.add( newJButton( "Button "+ count ) );
}
// create a JTabbedPane
JTabbedPane tabs = newJTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
// place each container on tabbed pane
tabs.addTab( "Horizontal Box", horizontal1 );
tabs.addTab( "Vertical Box with Struts", vertical1 );
tabs.addTab( "Horizontal Box with Glue", horizontal2 );
tabs.addTab( "Vertical Box with Rigid Areas", vertical2 );
tabs.addTab( "Vertical Box with Glue", panel );
getContentPane().add( tabs );
// place tabbed pane on content pane
setSize( 400, 220);
setVisible( true);
} // end constructor
publicstaticvoidmain( String args[] )
{
BoxLayoutDemo application = newBoxLayoutDemo();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
}
} // end class BoxLayoutDemo