/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tbox2;
import javax.swing.*;
import java.awt.*;
public class TBox2 extends JApplet {
Container container = null;
public void init() {
// 1. Get the handle on the applets' content pane
// and set the background color to white.
container = getContentPane();
container.setBackground(Color.white);
// 2. Create a horizontal box and add it to the applet.
Box baseBox = Box.createHorizontalBox();
container.add(baseBox);
// 3. Create a vertical box and add it to the base box.
Box vBox = Box.createVerticalBox();
baseBox.add(vBox);
// 4. Create button B1 and add it to vBox.
JButton b1 = new JButton("B1");
b1.setAlignmentX(Component.CENTER_ALIGNMENT);
b1.setMaximumSize(new Dimension(150,150));
vBox.add(b1);
// 5. Create a horizontal box and add it to vBox.
Box hBox = Box.createHorizontalBox();
vBox.add(hBox);
// 6. Create button B2 and add it to hBox.
JButton b2 = new JButton("B2");
b2.setAlignmentY(Component.CENTER_ALIGNMENT);
b2.setMaximumSize(new Dimension(75,100));
hBox.add(b2);
// 7. Create another button B3 and add it to hBox.
JButton b3 = new JButton("B3");
b3.setAlignmentY(Component.CENTER_ALIGNMENT);
b3.setMaximumSize(new Dimension(75,100));
hBox.add(b3);
// 8. Create the vertical box (vBox1) and
// add it to the base box.
Box vBox1 = Box.createVerticalBox();
baseBox.add(vBox1);
// 9. Create the button B4 and add it to vBox1.
JButton b4 = new JButton("B4");
b4.setAlignmentX(Component.CENTER_ALIGNMENT);
b4.setMaximumSize(new Dimension(100,250));
vBox1.add(b4);
}
}
Tidak ada komentar:
Posting Komentar