java的run代码 java runoob( 二 )


private JTextField textField_ ;
private JTextField textField;
private String url = System getProperty( user dir ) + \\ ;
private JTextPane textArea_ ;
private JTextArea textArea;
private static String cmd = first ;
private static Process pro = null;
private Thread InPutThread = null;
private Thread OutPutThread = null;
private Thread ErrorThread = null;
private JMenu File Edit;
private JMenuBar Part;
private JMenuItem Open InsertMain SaveAs Save Exit MarkColor;
private File file;
private String [] Keyword = { abstract default if private this boolean do implements protected throw break double import public throws byte else instanceof return transient case extends int short try catch final interface static void char finally long strictfp volatile class float native super while const for new switch continue goto package synchronized };
public static void main(String args[]) {
EventQueue invokeLater(new Runnable() {
public void run() {
try {
RunJava frame = new RunJava();
frame setVisible(true);
} catch (Exception e) {
e printStackTrace();
}
}
});
}
public RunJava() throws Exception {
super( Java代码运行器 );
File = new JMenu( 文件 );
Part = new JMenuBar();
Edit = new JMenu( 编辑 );
Part add(File);
Part add(Edit);
Open = new JMenuItem( 打开 );
Open addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg ) {
JFileChooser fileChooser = new JFileChooser(); // 实例化文件选择器
fileChooser setFileSelectionMode(JFileChooser FILES_AND_DIRECTORIES); // 设置文件选择模式 此处为文件和目录均可
if (fileChooser showOpenDialog(RunJava this) == JFileChooser APPROVE_OPTION) { // 弹出文件选择器 并判断是否点击了打开按钮
String fileName = fileChooser getSelectedFile() getAbsolutePath(); // 得到选择文件或目录的绝对路径
System out println(fileName);
file = new File(fileName);
InputData();
}
}
});
Save = new JMenuItem( 保存 );
Save addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg ) {
if(file==null){
JFileChooser fileChooser = new JFileChooser(); // 实例化文件选择器
【java的run代码 java runoob】 fileChooser setFileSelectionMode(JFileChooser FILES_AND_DIRECTORIES); // 设置文件选择模式 此处为文件和目录均可
if (fileChooser showSaveDialog(RunJava this) == JFileChooser APPROVE_OPTION) { // 弹出文件选择器 并判断是否点击了打开按钮
String fileName = fileChooser getSelectedFile() getAbsolutePath(); // 得到选择文件或目录的绝对路径
System out println(fileName);
file = new File(fileName);
OutputData();
}
}else{
OutputData();
}
}
});
SaveAs = new JMenuItem( 另存为 );
SaveAs addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg ) {
JFileChooser fileChooser = new JFileChooser(); // 实例化文件选择器
fileChooser setFileSelectionMode(JFileChooser FILES_AND_DIRECTORIES); // 设置文件选择模式 此处为文件和目录均可
if (fileChooser showSaveDialog(RunJava this) == JFileChooser APPROVE_OPTION) { // 弹出文件选择器 并判断是否点击了打开按钮
String fileName = fileChooser getSelectedFile() getAbsolutePath(); // 得到选择文件或目录的绝对路径
file = new File(fileName);
OutputData();
}
}
});
Exit = new JMenuItem( 退出 );
Exit addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg ) {
int j=JOptionPane showConfirmDialog(RunJava this 真的要退出吗? 退出 JOptionPane YES_OPTION JOptionPane QUESTION_MESSAGE);

推荐阅读