简易记事本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() {
【简易记事本java源代码 记事本怎么编写java】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程序代码天啊,冖_Na0 为什么会有我编的记事本代码呢???呵呵……你肯定是“请教”过我的吧??
呵呵……我自己编了一个,不过呢,没有windows那么多的功能啊 。
涉及到两个文件:
第一个文件中的代码:
package MyProject;
import java.awt.BorderLayout;

推荐阅读