import java.awt.*; import java.net.*; import java.io.*; import java.awt.event.*; public class Gui extends Frame { private MenuBar m_mb; private Menu m_file; private Menu m_command; private MenuItem m_new; private MenuItem m_open; private MenuItem m_save; private MenuItem m_save_as; private MenuItem m_exit; private MenuItem m_start; private MenuItem m_stop; private TextArea m_result; private TextArea m_script; private Font m_menufont; private Font m_scriptfont; public Gui() { super("Web Script: No Title"); // set up menu bar m_mb = new MenuBar(); setMenuBar(m_mb); // create menus m_file = new Menu("File"); m_mb.add(m_file); m_command = new Menu("Command"); m_mb.add(m_command); // set up "File" menu m_new = new MenuItem("New Script"); m_file.add(m_new); m_file.addSeparator(); m_open = new MenuItem("Open Script"); m_file.add(m_open); m_file.addSeparator(); m_save = new MenuItem("Save Script"); m_file.add(m_save); m_save_as = new MenuItem("Save as"); m_file.add(m_save_as); m_file.addSeparator(); m_exit = new MenuItem("Exit"); m_file.add(m_exit); // set up "Command" menu m_start = new MenuItem("Run Script"); m_command.add(m_start); m_stop = new MenuItem("Stop"); m_command.add(m_stop); // create textareas for script and result m_result = new TextArea(); m_result.setEditable(false); m_script = new TextArea(); // set up "File" menu action m_new.addActionListener(new FileCommand(FileCommand.NEW,this)); m_new.setShortcut(new MenuShortcut(KeyEvent.VK_F1)); m_open.addActionListener(new FileCommand(FileCommand.OPEN,this)); m_open.setShortcut(new MenuShortcut(KeyEvent.VK_F2)); m_save.addActionListener(new FileCommand(FileCommand.SAVE,this)); m_save.setShortcut(new MenuShortcut(KeyEvent.VK_F3)); m_save_as.addActionListener(new FileCommand(FileCommand.SAVEAS,this)); m_save_as.setShortcut(new MenuShortcut(KeyEvent.VK_F4)); m_exit.addActionListener(new FileCommand(FileCommand.EXIT,this)); m_new.setShortcut(new MenuShortcut(KeyEvent.VK_F9)); // set up "Command" menu action ExecutionCommand start = new ExecutionCommand(ExecutionCommand.START,this); ExecutionCommand stop = new ExecutionCommand(ExecutionCommand.STOP,this); m_start.addActionListener(start); m_start.setShortcut(new MenuShortcut(KeyEvent.VK_F7)); m_stop.addActionListener(stop); m_stop.setShortcut(new MenuShortcut(KeyEvent.VK_F8)); // set up menu Font m_menufont = new Font("Times Roman",Font.BOLD,12); m_file.setFont(m_menufont); m_command.setFont(m_menufont); m_new.setFont(m_menufont); m_open.setFont(m_menufont); m_save.setFont(m_menufont); m_save_as.setFont(m_menufont); m_exit.setFont(m_menufont); m_start.setFont(m_menufont); m_start.setFont(m_menufont); // set up script font m_scriptfont = new Font("Courier", Font.PLAIN,14); m_result.setFont(m_scriptfont); m_script.setFont(m_scriptfont); // set layout setLayout(new BorderLayout()); add("Center",m_result); add("South",m_script); pack(); } public TextArea getScript() { return m_script; } public String getCurrentScript() { return m_script.getSelectedText(); } public void clear() { m_result.setText(""); } public void display(String content) { m_result.append(content); } public static void main(String[] argvs) { Gui gui = new Gui(); gui.setSize(640,600); gui.show(); } }