View Javadoc
1 package jrre.gui; 2 3 import jrre.JRRE; 4 import java.net.*; 5 import java.awt.*; 6 import java.awt.event.*; 7 import javax.swing.*; 8 import javax.swing.JToolBar.*; 9 10 public class ControlGui extends JFrame implements ActionListener { 11 12 private ActionListener actionListenerList; 13 private JTextField stepCountField = new JTextField("10"); 14 15 public ControlGui(){ 16 17 super("JRRE Control"); 18 addWindowListener(new WindowDestroyer()); 19 20 Container content = getContentPane(); 21 content.setLayout(new BorderLayout()); 22 content.add(getToolBar(), BorderLayout.NORTH); 23 24 //setSize(200,400); 25 pack(); 26 setLocation(450, 650); 27 28 //if(JRRE.guiOn()) 29 setVisible(true); 30 } 31 32 public int getStepCount(){ 33 return Integer.parseInt(stepCountField.getText()); 34 } 35 36 private JToolBar getToolBar(){ 37 38 JToolBar toolBar = new JToolBar(); 39 JButton button; 40 41 String iconPath = 42 new String("lib/icons/toolbarButtonGraphics/"); 43 44 // Add run button. 45 URL iconUrl = this.getClass().getResource(iconPath+"media/Play24.gif"); 46 //button = new JButton(new ImageIcon(iconUrl)); 47 button = new JButton(new ImageIcon(iconPath+"media/Play24.gif")); 48 49 button.setToolTipText("Run"); 50 button.setActionCommand("Run"); 51 button.addActionListener(this); 52 toolBar.add(button); 53 54 // Add pause button 55 button = new JButton(new ImageIcon(iconPath+"media/Pause24.gif")); 56 button.setToolTipText("Pause"); 57 button.setActionCommand("Pause"); 58 button.addActionListener(this); 59 toolBar.add(button); 60 61 // Add halt button 62 button = new JButton(new ImageIcon(iconPath+"media/Stop24.gif")); 63 button.setToolTipText("Halt"); 64 button.setActionCommand("Halt"); 65 button.addActionListener(this); 66 toolBar.add(button); 67 68 // Add step button. 69 //iconUrl = this.getClass().getResource(iconPath+"Play24.gif"); 70 button = new JButton(new ImageIcon(iconPath+"media/StepForward24.gif")); 71 button.setToolTipText("Step"); 72 button.setActionCommand("Step"); 73 button.addActionListener(this); 74 toolBar.add(button); 75 76 stepCountField.setFont(new Font(null, Font.BOLD, 20)); 77 stepCountField.setColumns(2); 78 stepCountField.setToolTipText("Step Count"); 79 stepCountField.setActionCommand("Step"); 80 stepCountField.addActionListener(this); 81 toolBar.add(stepCountField); 82 83 // Add garbage collection button. 84 //iconUrl = this.getClass().getResource(iconPath+"Play24.gif"); 85 button = new JButton(new ImageIcon(iconPath+"general/Delete24.gif")); 86 button.setToolTipText("Collect Garbage"); 87 button.setActionCommand("Collect Garbage"); 88 button.addActionListener(this); 89 toolBar.add(button); 90 91 return toolBar; 92 } 93 94 /*** 95 * Handles action events fired by button presses and passes them 96 * to registered action listeners. 97 * @param Event fired. 98 */ 99 public void actionPerformed(ActionEvent event){ 100 101 String action = event.getActionCommand(); 102 103 ActionEvent newEvent = new ActionEvent(this, 104 ActionEvent.ACTION_PERFORMED, 105 action); 106 107 actionListenerList.actionPerformed(newEvent); 108 } 109 /*** 110 * Adds the specified ActionListener to the current collection of 111 * objects to notify when a event is fired. 112 * @param Action listener to add. 113 */ 114 public void addActionListener(ActionListener listener){ 115 actionListenerList = AWTEventMulticaster.add(actionListenerList, 116 listener); 117 } 118 119 } 120

This page was automatically generated by Maven