ui的java代码 ui写代码( 二 )


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(); // 实例化文件选择器
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);
if (j == JOptionPane YES_OPTION){
System exit( );
}
}
});
File add(Open);
File add(Save);
File add(SaveAs);
File add(Exit);
InsertMain = new JMenuItem( 新建 );
InsertMain addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg ) {
String str = public class test {\n
+public static void main(String[] args) {\n
+System out println(\ hello java\ );\n
+}\n + } ;
textArea_ setText(str);
textField setText(getName(textArea_ getText()));
}
});
MarkColor = new JMenuItem( 标注颜色 );
MarkColor addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
String str = public class test {\n
+public static void main(String[] args) {\n
+System out println(\ hello java\ );\n
+}\n + } ;
int a = str indexOf( class );
//System out println(a);
setDocs(str substring(a a+ ) Color RED true );
}
});
Edit add(InsertMain);
Edit add(MarkColor);
setJMenuBar(Part);
getContentPane() setLayout(null);
setBounds( );
setDefaultCloseOperation(JFrame EXIT_ON_CLOSE);
final JPanel panel = new JPanel();
panel setLayout(new BorderLayout());
panel setBounds( );
getContentPane() add(panel);
textArea_ = new JTextPane();

推荐阅读