Java完整简单记事本源代码.docx
《Java完整简单记事本源代码.docx》由会员分享,可在线阅读,更多相关《Java完整简单记事本源代码.docx(45页珍藏版)》请在冰豆网上搜索。
![Java完整简单记事本源代码.docx](https://file1.bdocx.com/fileroot1/2023-1/22/69914e91-d95c-49df-929f-9dd960461613/69914e91-d95c-49df-929f-9dd9604616131.gif)
Java完整简单记事本源代码
版权所有请勿抄袭
AboutDialog.java
packagenotepad;
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.ImageIcon;
importjavax.swing.JButton;
importjavax.swing.JDialog;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
publicclassAboutDialogimplementsActionListener{
publicJDialogDialog;
publicJButtonOK,Icon;
publicJLabelName,Version,Author,Java;
publicJPanelPanel;
AboutDialog(JFramenotepad,intx,inty){
Dialog=newJDialog(notepad,"AboutNotepad...",true);
OK=newJButton("OK");
Icon=newJButton(newImageIcon("Notepad.jpg"));
Name=newJLabel("Notepad");
Version=newJLabel("Version1.0");
Java=newJLabel("JREVersion6.0");
Author=newJLabel("Copyright(c)2011Sky.Norightsreserved.");
Panel=newJPanel();
Colorc=newColor(0,95,191);
Name.setForeground(c);
Version.setForeground(c);
Java.setForeground(c);
Panel.setBackground(Color.WHITE);
OK.setFocusable(false);
Dialog.setSize(280,180);
Dialog.setLocation(x,y);
Dialog.setResizable(false);
Dialog.setLayout(null);
Panel.setLayout(null);
OK.addActionListener(this);
Icon.setFocusable(false);
Icon.setBorderPainted(false);
Author.setFont(newFont(null,Font.PLAIN,11));
Panel.add(Icon);
Panel.add(Name);
Panel.add(Version);
Panel.add(Author);
Panel.add(Java);
Dialog.add(Panel);
Dialog.add(OK);
Panel.setBounds(0,0,280,100);
OK.setBounds(180,114,72,26);
Name.setBounds(80,10,160,20);
Version.setBounds(80,27,160,20);
Author.setBounds(15,70,250,20);
Java.setBounds(80,44,160,20);
Icon.setBounds(16,14,48,48);
}
publicvoidactionPerformed(ActionEvente){
Dialog.setVisible(false);
}
}
ColorDialog.java
packagenotepad;
importjava.awt.Color;
importjava.awt.Component;
importjava.awt.Font;
importjava.awt.GridLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.KeyEvent;
importjava.awt.event.KeyListener;
importjava.awt.event.WindowEvent;
importjava.awt.event.WindowListener;
importjavax.swing.JButton;
importjavax.swing.JDialog;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JTextArea;
importjavax.swing.JTextField;
publicclassColorDialogimplementsActionListener,WindowListener{
publicJDialogDialog;
publicJLabelNFL,NBL,SFL,SBL;
publicJTextAreaNormal,Selected;
publicJButtonNFB,NBB,SFB,SBB,OK,Cancel,Reset;
publicColorNFC,NBC,SFC,SBC;
publicColorChooserChooser;
publicColorDialog(JFramenotepad,intx,inty){
NFC=newColor(0,0,0);
NBC=newColor(249,249,251);
SFC=newColor(0,0,0);
SBC=newColor(191,207,223);
Dialog=newJDialog(notepad,"Color...",true);
NFL=newJLabel("NormalForeground:
");
NBL=newJLabel("NormalBackground:
");
SFL=newJLabel("SelectedForeground:
");
SBL=newJLabel("SelectedBackground:
");
Normal=newJTextArea("\nNormal正常");
Selected=newJTextArea("\nSelected选中");
NFB=newJButton("");
NBB=newJButton("");
SFB=newJButton("");
SBB=newJButton("");
OK=newJButton("OK");
Cancel=newJButton("Cancel");
Reset=newJButton("Reset");
Chooser=newColorChooser(Dialog,x+65,y-15);
Normal.setEditable(false);
Normal.setFocusable(false);
Normal.setFont(newFont("新宋体",0,16));
Normal.setForeground(NFC);
Normal.setBackground(NBC);
Selected.setEditable(false);
Selected.setFocusable(false);
Selected.setFont(Normal.getFont());
Selected.setForeground(SFC);
Selected.setBackground(SBC);
NFB.setBackground(NFC);
NBB.setBackground(NBC);
SFB.setBackground(SFC);
SBB.setBackground(SBC);
Dialog.setLayout(null);
Dialog.setLocation(x,y);
Dialog.setSize(410,220);
Dialog.setResizable(false);
Reset.setFocusable(false);
OK.setFocusable(false);
Cancel.setFocusable(false);
Dialog.add(Normal);
Dialog.add(Selected);
Dialog.add(NFL);
Dialog.add(NBL);
Dialog.add(SFL);
Dialog.add(SBL);
Dialog.add(SBB);
Dialog.add(SFB);
Dialog.add(NBB);
Dialog.add(NFB);
Dialog.add(OK);
Dialog.add(Cancel);
Dialog.add(Reset);
SBB.setBounds(144,100,60,22);
SFB.setBounds(144,70,60,22);
NBB.setBounds(144,40,60,22);
NFB.setBounds(144,10,60,22);
NFL.setBounds(10,10,130,22);
NBL.setBounds(10,40,130,22);
SFL.setBounds(10,70,130,22);
SBL.setBounds(10,100,130,22);
Normal.setBounds(220,10,174,56);
Selected.setBounds(220,66,174,56);
Reset.setBounds(10,160,74,24);
OK.setBounds(236,160,74,24);
Cancel.setBounds(320,160,74,24);
Dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Dialog.addWindowListener(this);
NFB.addActionListener(this);
NBB.addActionListener(this);
SFB.addActionListener(this);
SBB.addActionListener(this);
Reset.addActionListener(this);
OK.addActionListener(this);
Cancel.addActionListener(this);
}
publicvoidsetTextAreaColor(){
Normal.setForeground(NFB.getBackground());
Normal.setBackground(NBB.getBackground());
Selected.setForeground(SFB.getBackground());
Selected.setBackground(SBB.getBackground());
}
publicvoidcancel(){
Normal.setForeground(NFC);
Normal.setBackground(NBC);
Selected.setForeground(SFC);
Selected.setBackground(SBC);
NFB.setBackground(NFC);
NBB.setBackground(NBC);
SFB.setBackground(SFC);
SBB.setBackground(SBC);
Dialog.setVisible(false);
}
publicvoidactionPerformed(ActionEvente){
Objectobj=e.getSource();
if(obj==Reset){
NFB.setBackground(newColor(0,0,0));
NBB.setBackground(newColor(249,249,251));
SFB.setBackground(newColor(0,0,0));
SBB.setBackground(newColor(191,207,223));
setTextAreaColor();
}
elseif(obj==OK){
NFC=NFB.getBackground();
NBC=NBB.getBackground();
SFC=SFB.getBackground();
SBC=SBB.getBackground();
Dialog.setVisible(false);
}
elseif(obj==Cancel)
cancel();
else{
Chooser.init(((Component)obj).getBackground());
Chooser.Dialog.setVisible(true);
((Component)obj).setBackground(Chooser.New.getBackground());
setTextAreaColor();
}
}
publicvoidwindowClosing(WindowEvente){
cancel();
}
publicvoidwindowActivated(WindowEventarg0){}
publicvoidwindowClosed(WindowEventarg0){}
publicvoidwindowDeactivated(WindowEventarg0){}
publicvoidwindowDeiconified(WindowEventarg0){}
publicvoidwindowIconified(WindowEventarg0){}
publicvoidwindowOpened(WindowEventarg0){}
}
classColorChooserimplementsActionListener,WindowListener,KeyListener{
JDialogDialog;
JButtonChoice[][],Old,New,OK,Cancel;
JPanelPanel;
JTextFieldR,G,B;
JLabelOldLabel,NewLabel,RL,GL,BL;
ColorChooser(JDialogcolor,intx,inty){
Dialog=newJDialog(color,true);
Choice=newJButton[8][8];
Panel=newJPanel();
Old=newJButton("");
New=newJButton("");
OldLabel=newJLabel("Old:
");
NewLabel=newJLabel("New:
");
RL=newJLabel("R:
");
GL=newJLabel("G:
");
BL=newJLabel("B:
");
R=newJTextField("");
G=newJTextField("");
B=newJTextField("");
OK=newJButton("OK");
Cancel=newJButton("Cancel");
Panel.setLayout(newGridLayout(8,8,0,0));
inti=0,j=0;
Colorc;
Choice[0][7]=newJButton("");Choice[0][7].setBackground(newColor(255,255,255));
Choice[1][7]=newJButton("");Choice[1][7].setBackground(newColor(255,223,191));
Choice[2][7]=newJButton("");Choice[2][7].setBackground(newColor(255,207,207));
Choice[3][7]=newJButton("");Choice[3][7].setBackground(newColor(223,191,255));
Choice[4][7]=newJButton("");Choice[4][7].setBackground(newColor(207,207,255));
Choice[5][7]=newJButton("");Choice[5][7].setBackground(newColor(191,223,255));
Choice[6][7]=newJButton("");Choice[6][7].setBackground(newColor(207,255,207));
Choice[7][7]=newJButton("");Choice[7][7].setBackground(newColor(223,255,191));
for(i=0;i<8;i++){
c=Choice[i][7].getBackground();
for(j=0;j<8;j++){
if(j!
=7){
Choice[i][j]=newJButton("");
Choice[i][j].setBackground(newColor(c.getRed()*(j+1)/8,c.getGreen()*(j+1)/8,c.getBlue()*(j+1)/8));
}
Choice[i][j].setFocusable(false);
Choice[i][j].addActionListener(this);
Panel.add(Choice[i][j]);
}
}
Dialog.setSize(280,250);
Dialog.setLayout(null);
Dialog.setLocation(x,y);
Dialog.setResizable(false);
Dialog.add(Panel);
Panel.setBounds(10,10,160,160);
Dialog.add(Old);
Dialog.add(OldLabel);
Old.setEnabled(false);
Old.setBorderPainted(false);
Old.setBounds(214,10,44,22);
OldLabel.setBounds(180,10,44,22);
Dialog.add(New);
Dialog.add(NewLabel);
New.setEnabled(false);
New.setBorderPainted(false);
New.setBounds(214,32,44,22);
NewLabel.setBounds(180,32,44,22);
Dialog.add(R);
Dialog.add(G);
Dialog.add(B);
R.setBounds(214,97,44,22);
G.setBounds(214,123,44,22);
B.setBounds(214,149,44,22);
Dialog.add(RL);
Dialog.add(GL);
Dialog.add(BL);
RL.setBounds(196,97,16,22);
GL.setBounds(196,123,16,22);
BL.setBounds(196,149,16,22);
Dialog.add(OK);
Dialog.add(Cancel);
OK.setFocusable(false);
Cancel.setFocusable(false);
OK.setBounds(106,190,74,24);
Cancel.setBounds(190,190,74,24);
OK.addActionListener(this);
Cancel.addActionListener(this);
G.addKeyListener(this);
R.addKeyListener(this);
B.addKeyListener(this);
}
publicvoidsetText(Colorc){
R.setText(String.valueOf(c.getRed()));
G.setText(String.valueOf(c.getGreen()));
B.setText(String.valueOf(c.getBlue()));
}
publicvoidinit(Colorc){
New.setBackground(c);
Old.setBackground(c);
setText(c);
}
publicvoidactionPerformed(ActionEvente){
Objectobj=e.getSource();
if(obj==OK