求java版记事本源代码,急求!!!!!!

【要求】:
(1)GUI界面应该包括菜单栏、工具栏及状态栏;其中状态栏能动态显示系统时间
(2)实现记事本中的打开、保存功能、自动换行功能;另需添加字体、字号及颜色的设置、帮助窗口的打开等。
(3)实现编辑菜单里面的“查找和替换”功能、撤消功能;文字选中后的复制粘贴功能等。
要求加详细注释!!!!!!!!

楼主,留一个邮箱地址,发给你,以供借鉴!最主要还是培养自己的逻辑思维能力!

追问

要求加详细注释!!!!!630637613@qq.com

追答

图片

追问

要详细注释版的,我水平太低了,你帮我加上注释吧!再给我发一遍,谢谢了,我给你加分

追答

有时间给你加,正在工作之中。。。其实这些都是你需要学习的。。你可以自己将java GUI里的JFrame类,jbotton、线程等几个类搞清楚。。。

追问

我现在急着用!拜托了!帮帮我吧!

追答

我那个够详细了啊,,

追问

我刚学,最好全部注释!

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-06-24
import java.awt.event.ActionListener;
import java.util.EventListener;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.lang.*;
import java.awt.datatransfer.*;
import javax.swing.*;

public class MiniEdit extends JFrame implements ActionListener {

/**
* Method main
*
*
* @param args
*
*/
MenuBar menuBar = new MenuBar();
Menu file = new Menu("File"),
edit = new Menu("Edit"),
help = new Menu("Help");

MenuItem[] menuItem ={
new MenuItem("New"),
new MenuItem("Open"),
new MenuItem("Save"),
new MenuItem("Exit"),
new MenuItem("Select All"),
new MenuItem("Copy"),
new MenuItem("Cut"),
new MenuItem("Paste"),
new MenuItem("Help")
};

TextArea textArea = new TextArea();
String fileName = "NoName";
Toolkit toolKit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolKit.getSystemClipboard();

//opne and close message dialogs
private FileDialog openFileDialog =
new FileDialog(this,"Open File",FileDialog.LOAD);
private FileDialog saveFileDialog =
new FileDialog(this,"Save File",FileDialog.SAVE);

public static void main(String[] args) {
// TODO: Add your code here
MiniEdit MyEdit = new MiniEdit();
MyEdit.show();
}

/**
* Method MiniEdit
*
*
*/
public MiniEdit() {
// TODO: Add your code here
setTitle("MiniEdit");
setFont(new Font("Times New Roman",Font.PLAIN,15));
setBackground(Color.white);
setSize(500,500);

setMenuBar(menuBar);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(help);
for(int i=0;i<4;i++)
{
file.add(menuItem[i]);
edit.add(menuItem[i+4]);
}
help.add(menuItem[8]);
add(textArea);

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
e.getWindow().dispose();
System.exit(0);
}
});

//add actionListener
for(int i=0;i<menuItem.length;i++)
{
menuItem[i].addActionListener(this);
}

}

/**
* Method actionPerformed
*
*
* @param e
*
*/
public void actionPerformed(ActionEvent e) {
// TODO: Add your code here
Object eventSource = e.getSource();

if(eventSource == menuItem[0])//newItem
{
textArea.setText("");
}

else if(eventSource == menuItem[1])//OpenItem
{
openFileDialog.show();
fileName = openFileDialog.getDirectory()+openFileDialog.getFile();
if(fileName != null)
{
openFile(fileName);
}
}

else if(eventSource ==menuItem[2])//SaveItem
{
saveFileDialog.show();
fileName = saveFileDialog.getDirectory()+saveFileDialog.getFile();
if(fileName !=null)
{
writeFile(fileName);
}
}

else if(eventSource==menuItem[3])//exitItem
{
System.exit(0);
}

else if(eventSource == menuItem[4])//Select All
{
textArea.selectAll();
}
else if(eventSource == menuItem[5])//copy
{
String text = textArea.getSelectedText();
StringSelection selection= new StringSelection(text);

clipboard.setContents(selection,null);

}

else if(eventSource == menuItem[6])//cut
{
String text = textArea.getSelectedText();
StringSelection selection = new StringSelection(text);

clipboard.setContents(selection,null);
textArea.replaceText("",textArea.getSelectionStart(),
textArea.getSelectionEnd());
}

else if(eventSource == menuItem[7])//Paste
{
Transferable contents = clipboard.getContents(this);
if(contents==null)
return;
String text;
text="";
try{
text = (String)contents.getTransferData(DataFlavor.stringFlavor);

}catch(Exception ex){}
textArea.replaceText(text,
textArea.getSelectionStart(),textArea.getSelectionEnd());
}
else if(eventSource == menuItem[8])
{
// JOptionPane.showMessageDialog(null,"This is a MiniEdit.");
}

}

//Read file
public void openFile(String fileName){
try{
File file = new File(fileName);
FileReader readIn = new FileReader(file);
int size = (int)file.length();
int charsRead = 0;
char[] content = new char[size];
while(readIn.ready())
charsRead += readIn.read(content,charsRead,size-charsRead);
readIn.close();
textArea.setText(new String(content,0,charsRead));
}catch(Exception e)
{
System.out.println("Error opening file!");
}
}

//write file
public void writeFile(String fileName){
try{
File file = new File(fileName);
FileWriter write = new FileWriter(file);
write.write(textArea.getText());
write.close();
}catch(Exception e){
System.out.println("Error closing file!");

java windows记事本源代码
源代码:java import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;public class Notepad extends JFrame implements ActionListener { private JTextArea textArea;private JFileChooser fileChooser;private String filePath = ""; \/\/ 保存文件路径 private JButton saveB...

求JAVA记事本代码(十万火急!越快越好!)
给你程序基本功能实现了:import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.File;public class Test extends JFrame implements ActionListener { \/ \/ private static final long serialVersionUID = 1L;JMenu fileMenu, editorMenu, formatMenu; \/\/ 设置文件菜单,编辑...

求Java记事本源代码
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.sw...

求一个用JAVA写的简单的记事本源代码程序
import java.awt.*;import java.awt.event.*;import java.io.*;import java.awt.datatransfer.*;class MyMenuBar extends MenuBar{ public MyMenuBar(Frame parent){ parent.setMenuBar(this);} public void addMenus(String [] menus){ for(int i=0;i<menus.length;i++)add(new Menu(menus[i...

征求简单的日历记事本Java源代码
import java.awt.*;import java.awt.event.*;import java.io.*;public class Note extends Frame implements ActionListener{ private Menu filemenu = new Menu("文件");private Menu editmenu = new Menu("编辑");private Menu formatmenu = new Menu("格式");private Menu helpmenu = new ...

求个用JAVA编写的记事本程序!先谢谢了!!
import java.awt.*;import java.awt.event.*;import java.io.*;import java.awt.color.*;import java.awt.font.*;import javax.swing.undo.*;public class Note extends JFrame { boolean isChange=false;boolean wasChange=false;JMenuBar menuBar=new JMenuBar();JMenu menuFile=new JMenu("...

求JAVA小项目的完整代码
给你个做好了的Java的源程序的记事本,自己看看就行了的,不怎么难的···import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;public class MyNotepad implements ActionListener{ private JFrame frame=new JFrame("新记事本");private JTextArea jta=new ...

JAVA记事本 打开文件部分的代码
String fpath = fd.getDirectory();String fname = fd.getFile();BufferedReader br = new BufferedReader(new FileReader(fpath + fname));jta.setText("");\/\/JTextArea String s = br.readLine();while (s != null) { jta.append(s + "\\r\\n");s = br.readLine();} br.close(...

java记事本代码注释
frm.setTitle("小记事本");\/*将下拉式菜单menu1、menu2添加到菜单栏中*\/ menubar.add(menu1);menubar.add(menu2);\/*将菜单item1、item2添加到下拉式菜单menu1中,将菜单item3添加到下拉式菜单menu2中*\/ menu1.add(item1);menu1.add(item2);menu2.add(item3);\/*为item1、item2、item3...

如何用java编写日历记事本
1.打开一个记事本(windows里面自带那个)2.复制过去,保存为xxx.java(xxx是带main方法的那个类名)3.到sun网站下载一个JDK安装包进行安装 4.打开一个cmd窗口,进入保存xxx.java的目录,打入编译命令javac xxx.java 编译完成后(源代码没问题就会编译通过),打入运行命令 java xxx.java 5.正常的话...

相似回答