// CS184 Project 1 // Raul 'Joni' Chu - 12782756 - cs184-bq // Yuan Kui Shen - 12940472 - cs184-ac // File: GUIWindow.java // Class to implement a Java pop-up window which lets the user select what // type of atom to add the the VRML world. Types are represented as // ints (1-9). Actually communication with the world is handled with the // 'Talker' class since we can only extend one class and need to do so // with the Frame class in order to get a separate window. import java.awt.*; import java.awt.event.*; import vrml.*; import vrml.node.*; import vrml.field.*; import java.io.*; import java.util.*; public class GUIWindow extends Frame implements ActionListener, ItemListener, EventListener { boolean inAnApplet = true; private Choice Moles; private Label BondLabel; private String Bonds = "Single"; private String MoleculeName = "Hydrogen"; private int atom_type = 1; // Our pop-up window object public GUIWindow() { Panel bottomPanel = new Panel(); Panel centerPanel = new Panel(); setLayout(new BorderLayout()); bottomPanel.add(new Label("Molecule Type:")); Choice Moles = new Choice(); Moles.add("Hydrogen"); Moles.add("Oxygen - One Bond Site"); Moles.add("Oxygen - Two Bond Sites"); Moles.add("Carbon - Two Bond Site"); Moles.add("Carbon - Three Bond Sites"); Moles.add("Carbon - Four Bond Sites"); Moles.add("Nitrogen - One Bond Site"); Moles.add("Nitrogen - Two Bond Sites"); Moles.add("Nitrogen - Three Bond Sites"); bottomPanel.add(Moles); Moles.addItemListener(this); add("North", bottomPanel); add("South", centerPanel); } // Methods to keep JDK 1.1.x happy - why did they change the API on me like this? public void initialize() { } public void windowClosed(WindowEvent event) { } public void windowDeiconified(WindowEvent event) { } public void windowIconified(WindowEvent event) { } public void windowActivated(WindowEvent event) { } public void windowDeactivated(WindowEvent event) { } public void windowOpened(WindowEvent event) { } public void windowClosing(WindowEvent event) { if (inAnApplet) { dispose(); } else { System.exit(0); } } // When the user selects a type, we listen public void itemStateChanged(ItemEvent event) { Object source = event.getSource(); String name = ((Choice)source).getSelectedItem(); MoleculeName = name; if (MoleculeName == "Hydrogen") { atom_type = 1; System.out.println("1"); } else if (MoleculeName == "Oxygen - One Bond Site") { atom_type = 3; System.out.println("3"); } else if (MoleculeName == "Oxygen - Two Bond Sites") { atom_type = 2; System.out.println("2"); } else if (MoleculeName == "Carbon - Two Bond Site") { atom_type = 6; System.out.println("6"); } else if (MoleculeName == "Carbon - Three Bond Sites") { atom_type = 5; System.out.println("5"); } else if (MoleculeName == "Carbon - Four Bond Sites") { atom_type = 4; System.out.println("4"); } else if (MoleculeName == "Nitrogen - One Bond Site") { atom_type = 9; System.out.println("9"); } else if (MoleculeName == "Nitrogen - Two Bond Sites") { atom_type = 8; System.out.println("8"); } else { atom_type = 7; System.out.println("7"); } } // Used by Talker class to get the user's selection public int get_type() { return atom_type; } public void process_Event(EventObject event) { String EventName = (event.getSource()).toString(); System.out.println(EventName); show_controls(true); } public void show_controls(boolean show_them) { if (show_them) { this.setVisible(true); } } public void actionPerformed(ActionEvent event) { } }