package NoteBook;
import javaxswingJFrame;
import javaawt*;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJCheckBox;
import javaxswingJDialog;
import javaxswingJFileChooser;
import javaxswingJLabel;
import javaxswingJList;
import javaxswingJMenuBar;
import javaxswingJMenu;
import javaxswingJMenuItem;
import javaxswingJOptionPane;
import javaxswingJPanel;
import javaxswingJPopupMenu;
import javaxswingJScrollBar;
import javaxswingJScrollPane;
import javaxswingJTextArea;
import javaxswingJTextField;
import javaxswingScrollPaneLayout;
import javaxswingfilechooserFileSystemView;
import apachexmlinternalserializePrinter;
import javaio*;
import javatextSimpleDateFormat;
import javautil*;
import javautilList;
public class NoteBook implements ActionListener {
JFrame jf;
JTextArea jta;
JMenuItem[][] jmi;
myStack ms=new myStack();
public NoteBook(){
jf=new JFrame(记事本);
JMenuBar jmb=new JMenuBar();
jta=new JTextArea();
jfadd(jta);
mspush(jtagetText());
JScrollPane jsp=new JScrollPane(jta);
jfadd(jsp);
String[] str={文件编辑格式帮助};
String[][] str={{新建打开保存另存页面设置打印退出}
{撤销剪贴拷贝粘贴查找替换删除时间}
{字体}
{帮助主题关于记事本}};
JMenu[] jm=new JMenu[strlength];
// jmi=new JMenuItem[strlength][];//注意在这里定义有空指针异常!
for(int i=;i<strlength;i++){
jm[i]=new JMenu(str[i]);
Systemoutprintln(jm[i]);
jmbadd(jm[i]);
}
for(int i=;i<strlength;i++){
jmi=new JMenuItem[strlength][str[i]length];
for(int j=;j<str[i]length;j++){
if(equals(str[i][j])){
jm[i]addSeparator();//添加分割线
}else {
jmi[i][j]=new JMenuItem(str[i][j]);
jm[i]add(jmi[i][j]);
jmi[i][j]addActionListener(this);
}
}
}
jfadd(jmbBorderLayoutNORTH);//注意需要注明其放的位置不然会在左边
jfsetVisible(true);
jfpack();
Toolkit tk=ToolkitgetDefaultToolkit();
jfsetLocation((tkgetScreenSize()widthjfgetSize()width)/(tkgetScreenSize()heightjfgetSize()height)/);
jfsetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
public JTextArea getJTextArea(){
return thisjta;
}
public JFrame getJFrame(){
return thisjf;
}
public void actionPerformed(ActionEvent e) {
// TODO Autogenerated method stub
String str=egetActionCommand();
if(新建equals(str)){
new NoteBook();
}else if (打开equals(str)){
JFileChooser jfc=new JFileChooser();
jfcshowOpenDialog(null);//注意在这里的null表示对话框弹出的位置
if(jfcshowOpenDialog(null)==JFileChooserAPPROVE_OPTION){
File selectfile=jfcgetSelectedFile();
try {
FileReader reader=new FileReader(selectfile);
Scanner sc=new Scanner(reader);
while(schasNextLine()){
String line=scnextLine();
jtasetText(line);
}
try {
readerclose();//////////////////////阅读器需要关闭吗?///////////////////
} catch (IOException e) {
// TODO Autogenerated catch block
eprintStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Autogenerated catch block
eprintStackTrace();
}
}
if(jfcshowOpenDialog(null)==JFileChooserCANCEL_OPTION){
///////////////////////处理/////////////////////////////
javaxswingJOptionPaneshowMessageDialog(jfc你已经取消了);
}
}else if(保存equals(str)){
JFileChooser jfc=new JFileChooser();
jfcshowSaveDialog(null);//注意在这里的null表示对话框弹出的位置
if(jfcshowOpenDialog(null)==JFileChooserAPPROVE_OPTION){
File selectfile=jfcgetSelectedFile();
try {
PrintWriter pw=new PrintWriter(selectfile);//往文件里写
pwprint(jtagetText());
pwclose();//关闭///////////////////////////////////////////
} catch (FileNotFoundException e) {
// TODO Autogenerated catch block
eprintStackTrace();
}
}
if(jfcshowOpenDialog(null)==JFileChooserCANCEL_OPTION){
///////////////////////////////////添加//////////////////////////
javaxswingJOptionPaneshowMessageDialog(jfc你已经取消了);
}
}else if(另存equals(str)){
JOptionPane jop=new JOptionPane();
String filePath=jopshowInputDialog(请输入路径(型如C:/savetxt));//直接返回的是用户输入的信息!
// jopgetInputValue();//注意这种的到用户的输入是不对的
String str=^[cdefCDEF]:/[AZaZ]{}txt$;//路径正则表达式
Systemoutprintln(filePath);
if(filePathmatches(str)){//特别注意了政则表达式在后面
javaxswingJOptionPaneshowMessageDialog(jop文件路径真确);
}else {
javaxswingJOptionPaneshowMessageDialog(jop文件路径不对);
}
PrintWriter pw;
try {
pw = new PrintWriter(filePath);
pwprint(jtagetText());
pwclose();//关闭//////////////////////////
} catch (FileNotFoundException e) {
// TODO Autogenerated catch block
eprintStackTrace();
}//往文件里写
}else if(页面设置equals(str)){
javaxswingJOptionPaneshowMessageDialog(jf没有打印机);
}else if(打印equals(str)){
javaxswingJOptionPaneshowMessageDialog(jf没有打印机);
}else if(退出equals(str)){
jfdispose();//注意这是退出
}else if(撤销equals(str)){
String str=mspop();//出堆栈
jtasetText(str);
}else if(剪贴equals(str)){
mspush(jtagetText());//入堆栈
jtacut();
}else if(拷贝equals(str)){
py();
}else if(粘贴equals(str)){
mspush(jtagetText());//入堆栈
jtapaste();
}else if(查找equals(str)){
String str=JOptionPaneshowInputDialog(jf请输入查找内容);
StringBuffer strbuf=new StringBuffer(jtagetText());
int temp=strbufindexOf(str);
jtaselect(temp (temp+strlength()));
}else if(替换equals(str)){
mspush(jtagetText());//入堆栈
exchange myExchange=new exchange(this);
}else if(删除equals(str)){
mspush(jtagetText());//入堆栈
String str=jtagetSelectedText();
StringBuffer str=new StringBuffer(jtagetText());
strdelete(strindexOf(str) strindexOf(str)+strlength());
str=new String(str);
jtasetText(str);
}else if(时间equals(str)){
mspush(jtagetText());//入堆栈
Date dt=new Date();
SimpleDateFormat formater=new SimpleDateFormat();
formaterapplyPattern(yyyyMMddTHH:mm:ssSSSZ);
String str=formaterformat(dt);
StringBuffer sb=new StringBuffer(jtagetText());
String temp=new String(sbappend(str));
jtasetText(temp);
/////////////////加载时间////////////////////////
}else if(字体equals(str)){
mspush(jtagetText());//入堆栈
}else if(帮助主题equals(str)){
help myhelp=new help(this);
}else if(关于记事本equals(str)){
javaxswingJOptionPaneshowMessageDialog(jf该记事本用java语言编写作者瑚江水单位陕西科技大学时间——);
}
}
public static void main(String[] args){
NoteBook nb=new NoteBook();
}
}
////////////////////替换类////////////////////////
class exchange implements ActionListener{
JDialog jd;
JTextField jf;
JTextField jf;
JTextArea jta;
public exchange(Object obj){
if(obj instanceof NoteBook){
NoteBook nb=(NoteBook)obj;
jd=new JDialog(nbgetJFrame()替换);
jta=nbgetJTextArea();
}
jf=new JTextField();
jf=new JTextField();
JLabel jl=new JLabel(替换内容);
JLabel jl=new JLabel(替换对象);
JButton jb=new JButton(确定);
jbaddActionListener(this);
JButton jb=new JButton(取消);
jbaddActionListener(this);
JPanel jp=new JPanel(new FlowLayout());
jpadd(jl);
jpadd(jf);//替换内容
JPanel jp=new JPanel(new FlowLayout());
jpadd(jl);
jpadd(jf);//替换对象
JPanel jp=new JPanel(new FlowLayout());
jpadd(jb);jpadd(jb);
jdsetLayout(new GridLayout());
jdadd(jp);jdadd(jp);jdadd(jp);
jdsetSize( );
Toolkit tk=ToolkitgetDefaultToolkit();
jdsetLocation((tkgetScreenSize()widthjdgetSize()width)/(tkgetScreenSize()heightjdgetSize()height)/);
jdsetResizable(false);
jdsetVisible(true);
jdsetDefaultCloseOperation(JDialogDISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
// TODO Autogenerated method stub
Systemoutprintln(ok);
if(确定equals(egetActionCommand())){
String str=jfgetText();String str=jfgetText();
String str=new String(jtagetText());
str=strreplaceAll(str str);
jtasetText(str);javaxswingJOptionPaneshowMessageDialog(jd替换完成);
}
if(取消equals(egetActionCommand())){
jddispose();//关闭对话框
}
}
}
/////////////////帮助类///////////////////
class help implements ActionListener{
JDialog jd;
public help(Object obj){
if(obj instanceof NoteBook){
NoteBook nb=(NoteBook)obj;
jd=new JDialog(nbgetJFrame()help);
}
JMenuBar jmb=new JMenuBar();
JMenuItem jm=new JMenuItem(文件);
jmaddActionListener(this);
JMenuItem jm=new JMenuItem(编辑);
jmaddActionListener(this);
jmbadd(jm);jmbadd(jm);
jdadd(jmbBorderLayoutNORTH);
jdsetSize( );
Toolkit tk=ToolkitgetDefaultToolkit();
jdsetLocation((tkgetScreenSize()widthjdgetSize()width)/(tkgetScreenSize()heightjdgetSize()height)/);
jdsetResizable(false);
jdsetVisible(true);
jdsetDefaultCloseOperation(JDialogDISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
// TODO Autogenerated method
Systemoutprintln();
if(文件equals(egetActionCommand())){
javaxswingJOptionPaneshowMessageDialog(jd主要的功能有新建打开保存等具体的操作点击菜单即可);
}
if(编辑equals(egetActionCommand())){
javaxswingJOptionPaneshowMessageDialog(jd主要的功能有撤销剪贴粘贴复制删除等具体的操作点击菜单即可);
}
}
}
//////////////////////////我的堆栈///////////////////////
class myStack{
List list;
public myStack(){
list=new ArrayList();
}
public void push(Object obj){
if(obj instanceof String){
String str=(String)obj;
listadd(obj);
}else{
Systemexit();
}
}
public String pop(){
String obj=(String)listget(listsize());
listremove(listsize());
return obj;
}
}
////////////////////////////////////////////////////////////