/***************************************************************/ /* Program Name: Lab 5 Experiment View Code the VIEW */ /* */ /* */ /* Program Overview: */ /* Sample code for Lab 5 */ /* */ /* Input: */ /* There is no user input to this program. */ /* */ /* */ /***************************************************************/ import java.applet.AudioClip; // needed for the audio clip import java.awt.*; import javax.swing.*; import java.awt.event.*; // import classes for event handling import java.io.File; public class Lab5ExperimentView extends JFrame { Font myFont = new Font("Times",Font.ITALIC,14); Font myFontBold = new Font("Times",Font.BOLD,18); AudioClip ohSound; JButton cancel = new JButton("Cancel"); JButton display = new JButton("Display"); JCheckBox probation = new JCheckBox("Probation?"); JComboBox myChoice = new JComboBox(); JLabel label1 = new JLabel("Testing"); JLabel idLabel = new JLabel("ID Number",Label.RIGHT); DefaultListModel myModel = new DefaultListModel(); JList myList = new JList(myModel); JPanel panelTop = new JPanel(new GridLayout(1,4)); JPanel panelCenter = new JPanel(new GridLayout(2,2)); JPanel panelBottom = new JPanel(new GridLayout(1,1)); JLabel comments = new JLabel("What are the Options?"); JTextField id = new JTextField(10); public Lab5ExperimentView() { System.out.println(" At Method init"); setLayout(new BorderLayout()); // set JFrame background color and size cancel.setForeground(Color.red); display.setForeground(Color.blue); panelTop.setBackground(Color.cyan); panelCenter.setBackground(Color.green); getSoundsApp(); // get the sound from a file // ohSound.play( ); // play // set properties of individual widgets label1.setForeground(Color.red); label1.setFont(myFontBold); comments.setFont(myFontBold); idLabel.setForeground(Color.blue); idLabel.setFont(myFont); // add items to List widget myList.setBackground(Color.green); addItemsToWidgets(); // add Widgets to JPanels to JFrame panelTop.add(label1); panelTop.add(probation); panelTop.add(idLabel); panelTop.add(id); panelCenter.add(comments); panelCenter.add(myList); panelCenter.add(myChoice); panelBottom.add(display); panelBottom.add(cancel); // add JPanels to JFrame add(panelTop,BorderLayout.NORTH); add(panelCenter,BorderLayout.CENTER); add(panelBottom,BorderLayout.SOUTH); setTitle("5 Experiment Control"); setBounds(200,400,400,220); setVisible(true); } // remember to have the main method public static void main(String args[]) { new Lab5ExperimentView(); } public void addItemsToWidgets() { System.out.println(" At Method addItemToWidgets"); // add items to model of the List widget myModel.addElement("Math"); myModel.addElement("Business"); myModel.addElement("Biology"); myModel.addElement("Chemistry"); // add items to Choice widget myChoice.addItem("Soccer"); myChoice.addItem("Football"); myChoice.addItem("Baseball"); } public void getSoundsApp() { System.out.println("@ get Sounds in CONTROL as an APP"); File myFile; try{ myFile = new File("sounds/oh.wav"); ohSound = JApplet.newAudioClip(myFile.toURI().toURL()); } catch (Exception e) {} } }