Monday, April 9, 2007

BorderLayout

import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;

public class BoxLayoutTest{
//window
static JFrame window = new JFrame("Radio and Clickable Buttons");

public static void main(String[] args){
//
BoxLayoutTest boxlayout = new BoxLayoutTest();
Toolkit toolkit = window.getToolkit();
Dimension wndsize = toolkit.getScreenSize();
//center screen
window.setBounds(wndsize.width/4,wndsize.height/4,wndsize.width/2,wndsize.height/2);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}
//constructor
public BoxLayoutTest(){
//holder
Container content = window.getContentPane();
content.setLayout(new BorderLayout());

//radiobuttons
Box left = Box.createVerticalBox();
ButtonGroup radioGroup = new ButtonGroup();

//series of radio buttons
JRadioButton rbutton;
radioGroup.add(rbutton = new JRadioButton("Red"));
left.add(rbutton);

radioGroup.add(rbutton = new JRadioButton("Green"));
left.add(rbutton);

radioGroup.add(rbutton = new JRadioButton("Blue"));
left.add(rbutton);

radioGroup.add(rbutton = new JRadioButton("Yellow"));
left.add(rbutton);

//click boxes
Box right = Box.createVerticalBox();
right.add(new JCheckBox("Dashed"));
right.add(new JCheckBox("Thick"));
right.add(new JCheckBox("Rounded"));

//holder
Box top = Box.createHorizontalBox();
top.add(left);
top.add(right);

content.add(top,BorderLayout.CENTER);

//commands button
JPanel bottomPanel = new JPanel();
Border edge = BorderFactory.createRaisedBevelBorder();

//series of commands buttons
JButton button;
Dimension size = new Dimension(80,20);

bottomPanel.add(button = new JButton("Defaults"));
button.setBorder(edge);
button.setPreferredSize(size);

bottomPanel.add(button = new JButton("OK"));
button.setBorder(edge);
button.setPreferredSize(size);

bottomPanel.add(button = new JButton("Cancel"));
button.setBorder(edge);
button.setPreferredSize(size);
bottomPanel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

content.add(bottomPanel, BorderLayout.SOUTH);
content.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
}

No comments: