void doExeCommand() { JViewport viewport = scrollPane.getViewport(); String strContent = new String(); PSlider slider; int i; File fp = new File(dataFile); RandomAccessFile access = null; Runtime program = Runtime.getRuntime(); String cmdTrigger = "trigger"; boolean delete = fp.delete(); try { fp.createNewFile(); } catch (IOException ie) { System.err.println("Couldn't create the new file " + ie); // System.exit(-1);; } try { access = new RandomAccessFile(fp, "rw"); } catch (IOException ie) { System.err.println("Error in accessing the file " + ie); // System.exit(-1);; } for (i = 0; i < COMPONENTS; i++) { slider = (PSlider) vSlider.elementAt(i); /* Modified on March 20th to satisfy advisors' new request */ if (slider.isString == true) strContent = strContent + slider.getRealStringValue() + " "; else strContent = strContent + slider.getValue() + " "; } // Get value of the radio button group if (firstBox.isSelected() == true) strContent = strContent + "1"; else strContent = strContent + "0"; try { access.writeBytes(strContent); access.close(); } catch (IOException ie) { System.err.println("Error in writing to file " + ie); // System.exit(-1);; } // Trigger the OpenGL program to update with new values try { Process pid = program.exec(cmdTrigger); } catch (IOException ie) { System.err.println("Couldn't run " + ie); // System.exit(-1);; } doSourceFileUpdate(); }
public OrderTrans2() { super(windowTitle); int i; int currentPanel; // Value to specify which is the current panel in the vector JPanel subPanel = new JPanel(); // value used when adding sliders to the frame Runtime program = Runtime.getRuntime(); Container content = getContentPane(); createSliderVector(); createPanelVector(); getCodeSwapString(); /** Set code-swap strings' value. */ /** Get current OS of the system. */ if (System.getProperty("os.name").startsWith("Windows")) isWindows = true; else isWindows = false; /** Add the radio buttons to the group */ radioGrp.add(firstBox); radioGrp.add(secondBox); /** 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"); // Create the main panel that contains everything. JPanel mainPanel = new JPanel(); // Create the panel that contains the sliders JPanel subPanel1 = new JPanel(); // Create the panel that contains the checkboxes JPanel subPanel2 = new JPanel(); // Create the panel that contains the buttons JPanel subPanel3 = 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); mainPanel.add(subPanel3); 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++) { PSlider 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, 2)); subPanel2.add(firstBox); subPanel2.add(secondBox); subPanel3.setLayout(new GridLayout(0, 3)); subPanel3.add(exeButton); exeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExeCommand(); } }); subPanel3.add(resetButton); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doResetCommand(); } }); subPanel3.add(exitButton); exitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExitCommand(); } }); /** Run the illustrated program */ try { pid = program.exec(cmd); if (isWindows == false) { Process pid2 = null; pid2 = program.exec("getpid " + cmd.substring(4)); } } 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(dataFile); doResetCommand(); boolean delete = fp.delete(); pid.destroy(); } }); doExeCommand(); setSize(WIDTH, HEIGHT); setLocation(500, 0); setVisible(true); }