📄 sentencesgen.java
字号:
// public boolean validation() { for(int i=0; i < labelReference.size(); i++) { // code to use if the data is an enumerated type // if(blockType.get(i).equals("enum")) { // set the vertex's value to match the newly selected one // cfgVertexFocus.values.set(i, (String)((JComboBox)enteredData.get(i)). getSelectedItem()); } // code to use if the data is a text field // if(blockType.get(i).equals("text")) { String text =((JTextField)enteredData.get(i)).getText(); text = text.trim(); cfgVertexFocus.values.set(i,text); } // code to use if the data is a vector field // if(blockType.get(i).equals("vector")) { String text =((JTextField)enteredData.get(i)).getText(); text = text.trim(); cfgVertexFocus.values.set(i,text); } // code to get information from a check box // if(blockType.get(i).equals("boolean")) { boolean status = ((JCheckBox)enteredData.get(i)).isSelected(); String value = new String(); if(status){ value = "true"; } else { value = "false"; } digraph.tmpepi = "" + value; //cfgVertexFocus.values.set(i,value); } // code to get information from a float variable // if(blockType.get(i).equals("float")) { String text = ((JTextField)enteredData.get(i)).getText(); try { float value = Float.valueOf(text).floatValue(); //cfgVertexFocus.values.set(i, text); //System.out.println("text="+ text); digraph.tmpweight = ""+text; } catch (java.lang.NumberFormatException event) { JFrame frame = new JFrame("Warning"); String warningMessage = new String("The value entered for " + cfgVertexFocus.names.get(i) + " is not a floating point number."); JOptionPane.showMessageDialog(frame, warningMessage); return false; } } // code to get information from a double variable // if(blockType.get(i).equals("double")) { String text = ((JTextField)enteredData.get(i)).getText(); try { double value = Double.valueOf(text).doubleValue(); cfgVertexFocus.values.set(i, text); } catch (java.lang.NumberFormatException event) { JFrame frame = new JFrame("Warning"); String warningMessage = new String("The value entered for " + cfgVertexFocus.names.get(i) + " is not a floating point number."); JOptionPane.showMessageDialog(frame, warningMessage); return false; } } // code to get information from an unsigned integer variable // if(blockType.get(i).equals("unsigned-integer")) { String text = ((JTextField)enteredData.get(i)).getText(); try { int value = Integer.valueOf(text).intValue(); if (value >= 0) { cfgVertexFocus.values.set(i, text); } else { JFrame frame = new JFrame("Warning"); String warningMessage = new String("The value entered for " + cfgVertexFocus.names.get(i) + " is not an unsigned integer."); JOptionPane.showMessageDialog(frame,warningMessage); return false; } } catch (java.lang.NumberFormatException event) { JFrame frame = new JFrame("Warning"); String warningMessage = new String("The value entered for " + cfgVertexFocus.names.get(i) + " is not an unsigned integer."); JOptionPane.showMessageDialog(frame, warningMessage); return false; } } // code to get information from an integer variable // if(blockType.get(i).equals("integer")) { String text = ((JTextField)enteredData.get(i)).getText(); try { int value = Integer.valueOf(text).intValue(); cfgVertexFocus.values.set(i, text); } catch (java.lang.NumberFormatException event) { JFrame frame = new JFrame("Warning"); String warningMessage = new String("The value entered for " + cfgVertexFocus.names.get(i) + " is not an integer."); JOptionPane.showMessageDialog(frame, warningMessage); return false; } } } return true; } */ // method: actionPerformed // // arguments: // ActionEvent e: event that was fired // // return : none // // listens for actions taking place on the components // public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("run")){ String s = null; int randomNumber = random.nextInt(); randomNumber = Math.abs(randomNumber); randomNumber = (randomNumber % 500) + 1; try { String tmpPath = digraph.lmtesterFile.getAbsolutePath(); String[] command = {"","-length", "100","-seed", "10", "-g", ""}; String randomStr = ""+randomNumber; command[0] = GUI_PATH + "/util/speech/isip_lm_tester/isip_lm_tester.exe"; command[4] = randomStr; command[6] = tmpPath; // run the Utitlity "isip_lm_tester.exe ***" command // Process p = Runtime.getRuntime().exec(command); p.waitFor(); System.out.println("return code: " + p.exitValue()); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command // while ((s = stdInput.readLine()) != null) { sentences+=s; sentences+="\n"; } // read any errors from the attempted command // while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e1) { System.out.println("exception happened - here's what I know: "); e1.printStackTrace(); System.exit(-1); } catch(InterruptedException e2) { System.err.println("Exception:" + e2.getMessage()); } textArea.setText(sentences); workArea.repaint(); } if(e.getActionCommand().equals("cancel")){ // dispose of the changes and revert to the old ways // this.dispose(); } if(e.getActionCommand().equals("save")){ // dispose of the changes and revert to the old ways // JFileChooser saveChooser = null; String cwd = System.getProperty("user.dir"); saveChooser = new JFileChooser(cwd); // set the font and button text for the save chooser // saveChooser.setFont(newFont); String saveApprove = new String("Save"); saveChooser.setApproveButtonText(saveApprove); // display the file chooser object // int returnVal = saveChooser.showOpenDialog(digraph); // check to see if a file was selected by the user // if (returnVal == JFileChooser.APPROVE_OPTION) { // retrieve the selected file // resultFile = saveChooser.getSelectedFile(); // write the parameters to file // writeResult(); } } if(e.getActionCommand().equals("help")){ // display a help message: "under construction" // JFrame frame = new JFrame("Help"); JOptionPane.showMessageDialog(frame, "The help message is under construction"); } } // method: writeResult // // arguments: none // return : none // // writes the sof file // public void writeResult() { // declare local variables // FileOutputStream fout = null; PrintWriter file = null; String line = null; // open the selected file for writing // try { // initialize the variables // line = new String(); // initialize the file output stream // fout = new FileOutputStream(resultFile); file = new PrintWriter(fout); file.println(sentences); // close the file descriptor // file.close(); } // catch and deal with any file I/O exceptions // catch(IOException e1) {} }}//// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -