java记事本开发源代码 java简单记事本源代码( 九 )


fc.show();
if(fc.getFile()!=null){
File file = new File(fc.getFile());
try {
PrintWriter pw = new PrintWriter(file);
pw.print(textArea1.getText());
pw.flush();
pw.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
else{
return;
}
}
private void menuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
fc.show();
if(fc.getFile()!=null){
File file = new File(fc.getFile());
try {
PrintWriter pw = new PrintWriter(file);
pw.print(textArea1.getText());
pw.flush();
pw.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
else{
return;
}
}
private void menuItem8ActionPerformed(java.awt.event.ActionEvent evt) {
Transferable contents = clipboard.getContents(this);
DataFlavor flavor = DataFlavor.stringFlavor;
if(contents.isDataFlavorSupported(flavor))
try{
String str;
str=(String)contents.getTransferData(flavor);
textArea1.append(str);
}catch(Exception e){}
}
private void menuItem7ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = this.textArea1.getSelectedText();
StringSelection text = new StringSelection(temp);
clipboard.setContents(text,null);
}
private void menuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = this.textArea1.getSelectedText();
StringSelection text = new StringSelection(temp);
clipboard.setContents(text,null);
int start = textArea1.getSelectionStart();
int end = textArea1.getSelectionEnd();
textArea1.replaceRange("",start,end);
}
private void open(java.awt.event.ActionEvent evt) {
fc.show();
if(fc.getFile()!=null){
File file = new File(fc.getFile());
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String s;
try {
while((s= br.readLine())!=null){
textArea1.append(s+"\n");
}
fr.close();
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
else{
return;
}
}
private void newText(java.awt.event.ActionEvent evt) {
this.textArea1.setText("");
}
private void exit(java.awt.event.ActionEvent evt) {
System.exit(0);
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WriteBoard().setVisible(true);
}
});
}
// Variables declaration - do not modify
private java.awt.Menu menu1;
private java.awt.Menu menu2;
private java.awt.MenuBar menuBar1;
private java.awt.MenuItem menuItem1;
private java.awt.MenuItem menuItem2;
private java.awt.MenuItem menuItem3;
private java.awt.MenuItem menuItem4;
private java.awt.MenuItem menuItem5;
private java.awt.MenuItem menuItem6;
private java.awt.MenuItem menuItem7;
private java.awt.MenuItem menuItem8;
private java.awt.TextArea textArea1;
// End of variables declaration
}
使用记事本编写JAVA程序,并运行输出结果,具体的实现步骤是什么?1、首先在电脑中新建一个记事本,将记事本的后缀改为“.java” , 如下图所示 。
2、然后使用记事本的方式打开,输入java程序代码,如下图所示 。
3、接着在键盘上按“win+R”快捷键键打开运行 , 输入“cmd”,如下图所示 。
4、在命令行输入“D:” , 按“Enter”键进去D盘,再输入“cd Desktop”进去Desktop文件夹,如下图所示 。

推荐阅读