import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Main { //*1 Main window, with BorderLayout
public static void main (String [] args) {
java.awt.EventQueue.invokeLater (new Runnable() {
public void run() {
new Main ();
}
});
}
public Main () {
// Window setup
JFrame frame = new JFrame();
frame.setLocation (100, 100);
frame.setSize (500, 500);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setLayout (new BorderLayout()); //*1
// Text field at top
JTextField urlField = new JTextField ("http://www.cs.tufts.edu", 30); //*2 JTextField, as NORTH
urlField.setBorder (new LineBorder(Color.BLUE, 2));
frame.add (urlField, BorderLayout.NORTH); //*2
// Drawing canvas in middle
JPanel canvas = new JPanel (); //*3 JPanel (drawing area), as CENTER
canvas.setBorder (new LineBorder(Color.RED, 2));
frame.add (canvas, BorderLayout.CENTER); //*3
// Control panel at bottom
JPanel controls = new JPanel (); //*4 JPanel, as SOUTH, with FlowLayout
controls.setBorder (new LineBorder(Color.BLUE, 2));
controls.setLayout (new FlowLayout ()); //*4
// Put this inside the control panel
String[] comboStrings = { "Forward", "Back", "Home" };
JComboBox<String> combo = new JComboBox<String> (comboStrings); //*5 JComboBox and 2 JButtons
controls.add (combo); //*5
// These 2 buttons inside control panel also
JButton reloadButton = new JButton ("Reload"); //*5
controls.add (reloadButton); //*5
JButton stopButton = new JButton ("Stop"); //*5
controls.add (stopButton); //*5
// Now plug the control panel into the main frame
frame.add (controls, BorderLayout.SOUTH); //*4
// Settings panel on right
JPanel settings = new JPanel (); //*6 JPanel, as EAST, with GridLayout
settings.setBorder (new LineBorder(Color.BLUE, 2));
settings.setLayout (new GridLayout (5, 1)); //*6
// Put these inside the settings panel
JLabel label = new JLabel ("Settings:"); //*7 JLabel and JCheckBox'es
settings.add (label); //*7
JCheckBox graphicsCB = new JCheckBox ("Graphics", true); //*7
settings.add (graphicsCB); //*7
JCheckBox animationCB = new JCheckBox ("Animation", true); //*7
settings.add (animationCB); //*7
JCheckBox javascriptCB = new JCheckBox ("Javascript", false); //*7
settings.add (javascriptCB); //*7
JCheckBox cookiesCB = new JCheckBox ("Cookies", false); //*7
settings.add (cookiesCB); //*7
// Now plug the settings panel into the main frame
frame.add (settings, BorderLayout.EAST); //*6
// And show the whole window
frame.setVisible (true);
}
}