void doResetCommand() { int i; PSlider slider; for (i = 0; i < COMPONENTS; i++) { slider = (PSlider) vSlider.elementAt(i); if (slider.isInteger == true) slider.setValue(slider.getIntDefaultValue()); else slider.setValue(slider.getFloatDefaultValue()); } doExeCommand(); }
public WinSize() { super(windowTitle); int i; int currentPanel; // Value to specify which is the current panel in the vector int X = 0; int Y = 0; PSlider slider = null; JPanel subPanel = new JPanel(); // value used when adding sliders to the frame Runtime program = Runtime.getRuntime(); Container content = getContentPane(); createSliderVector(); createPanelVector(); /** Get current OS of the system. */ if (System.getProperty("os.name").startsWith("Windows")) isWindows = true; else isWindows = false; /** Set interactive buttons for the user interface */ JButton exeButton = new JButton("Execute"); exeButton.setToolTipText("Re-execute the program"); JButton resetButton = new JButton("Reset"); resetButton.setToolTipText("Reset Value"); JButton exitButton = new JButton("Exit"); exitButton.setToolTipText("Exit the Program"); if (COMPONENTS == 0) { exeButton.setVisible(false); resetButton.setVisible(false); } JPanel mainPanel = new JPanel(); JPanel subPanel1 = new JPanel(); JPanel subPanel2 = new JPanel(); // JScrollPane scrollPane = new JScrollPane(); // main text pane with scroll bars content.add(mainPanel, BorderLayout.SOUTH); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); content.add(scrollPane, BorderLayout.CENTER); scrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); scrollPane.getViewport().add(textPane); mainPanel.add(subPanel1); mainPanel.add(subPanel2); subPanel1.setLayout(new GridLayout(0, 1)); /** Add subPanel elements to the subPanel1, each would be a row of sliders */ for (i = 0; i < ROWS; i++) subPanel1.add((JPanel) vSubPanel.elementAt(i)); /** Set the first element in the Panel Vector as the current subPanel. */ currentPanel = 0; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); /** Allocate sliders to the sub-panels. */ for (i = 0; i < COMPONENTS; i++) { slider = (PSlider) vSlider.elementAt(i); if (slider.getResideValue() == 'n') { currentPanel += 1; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); } subPanel.add((PSlider) vSlider.elementAt(i)); } /** Set and view the source code on the frame */ textPane.setEditable(false); textPane.setContentType("text/html; charset=EUC-JP"); subPanel2.setLayout(new GridLayout(0, 3)); subPanel2.add(exeButton); exeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExeCommand(); } }); subPanel2.add(resetButton); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doResetCommand(); } }); subPanel2.add(exitButton); exitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExitCommand(); } }); /** Run the illustrated program */ slider = (PSlider) vSlider.elementAt(0); X = slider.getIntDefaultValue(); slider = (PSlider) vSlider.elementAt(1); Y = slider.getIntDefaultValue(); try { pid = program.exec(cmd + " " + X + " " + Y); if (isWindows == false) { Process pid2 = null; pid2 = program.exec("getpid WinSize"); } } catch (IOException ie) { System.err.println("Couldn't run " + ie); System.exit(-1); } /** Set the initial status for the window */ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { // File fp = new File("link"); // boolean delete = fp.delete(); doResetCommand(); pid.destroy(); } }); doSourceFileUpdate(); setSize(WIDTH, HEIGHT); setLocation(500, 0); setVisible(true); }