/***************************************************************/ /* Program Name: Lab7 Experiment Code the CONTROL */ /* */ /* */ /* Program Overview: */ /* Sample code for Lab 7 */ /* */ /* FULL M V C */ /* */ /* */ /* */ /***************************************************************/ import java.awt.event.*; import javax.swing.JList; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class Lab7ExpControl extends Lab7ExpView implements ActionListener, ListSelectionListener { public Lab7ExpModel m = new Lab7ExpModel(this); double result; public static void main(String args[]) { // Construct the frame new Lab7ExpControl(); } public Lab7ExpControl() { System.out.println("@ constructor Control Class"); // add listeners bCompute.addActionListener(this); bStop.addActionListener(this); ccChoice.addListSelectionListener(this); } public void actionPerformed(ActionEvent e) { System.out.println("@ actionPerformed in Control Class"); if (e.getSource() == bCompute) { result = m.pCompute(inputTF.getText()); if (result !=0 ) outputL.setText(" SQRT is " + decimal.format(result)); else outputL.setText(" invalid number please retype "); } else if (e.getSource() == bStop) m.pStop(); } public void valueChanged(ListSelectionEvent i) { JList source = (JList) i.getSource(); System.out.println("@ valueChanged in Control Class"); if (i.getSource() == ccChoice && ccChoice.getSelectedIndex() == 0 ) { System.out.println("Please select a Sound "); outputL.setText("Please select a sound"); } else if (i.getSource() == ccChoice && ccChoice.getSelectedIndex() == 1 ) sa.play(); else if (i.getSource() == ccChoice && ccChoice.getSelectedIndex() == 2 ) sb.play(); else if (i.getSource() == ccChoice && ccChoice.getSelectedIndex() == 3 ) sc.play(); else if (i.getSource() == ccChoice && ccChoice.getSelectedIndex() == 4 ) sd.play(); } }