// CG.java // // Mark F. Hulber // May 1996 // // CG lays out and initializes the environment for the CG Drawing Board. // Instantiations include the drawing board, buttons, a text field and // other panels. The class Events inherits from CG and handles the // events associated with all of the panels on the drawing board. // // import java.awt.*; public class CG extends Frame { Button clear, quit, about; Choice algo; TextField textarea; WorkArea workarea; Font thefont; Panel panel1, panel2; Panel buttonpanel; GridBagLayout gridbag = new GridBagLayout(); public CG(String title){ super(title); thefont = new Font("Helvetica", Font.BOLD, 14); clear = new Button("Clear"); clear.setForeground(Color.white); clear.setBackground(Color.black); clear.setFont(thefont); quit = new Button("Quit"); quit.setForeground(Color.white); quit.setBackground(Color.black); quit.setFont(thefont); about = new Button("About"); about.setForeground(Color.white); about.setBackground(Color.black); about.setFont(thefont); algo = new Choice(); algo.addItem("Gift Wrap"); algo.addItem("Graham Scan"); algo.setForeground(Color.white); algo.setBackground(Color.black); algo.setFont(thefont); textarea = new TextField(25); textarea.setForeground(Color.white); textarea.setBackground(Color.black); textarea.setFont(thefont); textarea.setEditable(false); workarea = new WorkArea(clear, textarea, algo); workarea.setForeground(Color.yellow); workarea.setBackground(Color.blue); workarea.setFont(thefont); panel2 = new Panel(); panel2.setForeground(Color.white); panel2.setBackground(Color.black); panel2.setFont(thefont); panel2.setLayout(gridbag); constrain(panel2, new Label("Info"), 0, 0, 1, 1); constrain(panel2, textarea, 0, 1, 1, 3, GridBagConstraints.NONE, GridBagConstraints.WEST, 1.0, 0.0, 0, 0, 0, 0); constrain(panel2, new Label("Drawing Area"), 0, 4, 1, 1, 10, 0, 0, 0); constrain(panel2, workarea, 0, 5, 1, 5, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1.0, 1.0, 0, 0, 0, 0); buttonpanel = new Panel(); buttonpanel.setForeground(Color.white); buttonpanel.setBackground(Color.black); buttonpanel.setFont(thefont); buttonpanel.setLayout(new FlowLayout()); buttonpanel.setLayout(gridbag); constrain(buttonpanel, clear, 0, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER, 0.3, 0.0, 0, 0, 0, 0); constrain(buttonpanel, quit, 1, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER, 0.3, 0.0, 0, 0, 0, 0); constrain(buttonpanel, about, 2, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER, 0.3, 0.0, 0, 0, 0, 0); constrain(buttonpanel, algo, 3, 0, 1, 1, GridBagConstraints.NONE, GridBagConstraints.CENTER, 0.3, 0.0, 0, 0, 0, 0); this.setLayout(gridbag); constrain(this, panel2, 1, 0, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1.0, 1.0, 10, 10, 5, 10); constrain(this, buttonpanel, 0, 1, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 1.0, 0.0, 5, 0, 0, 0); } public void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height, int fill, int anchor, double weight_x, double weight_y, int top, int left, int bottom, int right) { GridBagConstraints c = new GridBagConstraints(); c.gridx = grid_x; c.gridy = grid_y; c.gridwidth = grid_width; c.gridheight = grid_height; c.fill = fill; c.anchor = anchor; c.weightx = weight_x; c.weighty = weight_y; if (top+bottom+left+right>0) c.insets = new Insets(top, left, bottom, right); ((GridBagLayout)container.getLayout()).setConstraints(component, c); container.add(component); } public void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height) { constrain(container, component, grid_x, grid_y, grid_width, grid_height, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0, 0, 0, 0, 0); } public void constrain(Container container, Component component, int grid_x, int grid_y, int grid_width, int grid_height, int top, int left, int bottom, int right) { constrain(container, component, grid_x, grid_y, grid_width, grid_height, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0, top, left, bottom, right); } public static void main(String[] args) { Frame f = new CG("CG Drawing Board 1.0"); f.pack(); f.show(); } }