给大家分享下我之前的作品:

源文件下载:

  链接:https://pan.baidu.com/s/1N45VsS9aVgmvhvYjRLxBrA 
  提取码:b9fg 

源码:

  JF_Notpad.java实现主要面板,在二级菜单可以实现java模板建立,可以后期自己添加:

  

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*; //导入菜单
import javax.swing.filechooser.FileNameExtensionFilter;
import java.util.Date; //获取系统的时间
import java.text.SimpleDateFormat; //控制系统的时间格式 import java.awt.event.*;
import java.io.*;
import java.util.regex.*; public class JF_Notpad extends JFrame implements ActionListener,WindowListener{
//menuBar
private JMenuBar mb;
private JMenu file,edit,format,view,help; //menuToolBar
private JToolBar tool;
private static int BUTTONWIDTH,BUTTONHEIGHT;
private JButton create,unfold,copy,cut,paste,pasteShortcut,delete; //File
//JMenu下还可以有二级菜单
private JMenu newNot;
//JMenuItem不可以有其他菜单
private JMenuItem notpad,model,open,save,saveAs,pageSet,print,exit; //Edit
private JMenuItem undoE,cutE,copyE,pasteE,deleteE,findE,findNextE,replaceE,goToE,selectAllE,timeDateE; //Format
private JMenuItem wordWrap,font; //View
private JMenuItem statusBar; //Help
private JMenuItem viewHelp,about; //leftSpace
private JPanel leftSpace; //TextArea
private JTextArea content;
private JScrollPane scroll; //openUrl,saveUrl
private static String openUrl="E:/notpad.txt"; //保存之前打开文件的路径
private static String saveUrl="E:/notpad.txt"; //保存之前保存文件的路径
private boolean saved=false; //判断文件是否保存过 //contentFont 字体
private Font contentFont; //是否在打开保存面板后,还应该打开选择文件面板
private boolean openFileBool=false; public static void main(String[] args) {
JF_Notpad not=new JF_Notpad();
} public static JButton changeIconSize(JButton button,String url,int width,int height,String tip){
button.setBounds(0,0,width,height);
ImageIcon buttonImg=new ImageIcon(url);
//改变图片的大小
Image temp=buttonImg.getImage().getScaledInstance(button.getWidth(), button.getHeight(), buttonImg.getImage().SCALE_DEFAULT);
button=new JButton(new ImageIcon(temp));
button.setToolTipText(tip); //提示 return button;
} public static Image changeImageSize(String url,int width,int height){
ImageIcon Img=new ImageIcon(url);
//改变图片的大小
Image temp=Img.getImage().getScaledInstance(width, height, Img.getImage().SCALE_DEFAULT); return temp;
} JF_Notpad(){
//menubar
mb=new JMenuBar();
file=new JMenu("File(F)");
file.setMnemonic('F');
edit=new JMenu("Edit(E)");
edit.setMnemonic('E');
format=new JMenu("Format(O)");
format.setMnemonic('O');
view =new JMenu("View(V)");
view.setMnemonic('V');
help=new JMenu("Help(H)");
help.setMnemonic('H'); //menuToolBar
tool=new JToolBar();
BUTTONWIDTH=22;
BUTTONHEIGHT=22; create=new JButton();
create=JF_Notpad.changeIconSize(create, "img/notpad/news.png", BUTTONWIDTH, BUTTONWIDTH, "New");
unfold=new JButton();
unfold=JF_Notpad.changeIconSize(unfold, "img/notpad/open.png", BUTTONWIDTH, BUTTONWIDTH, "Open");
copy=new JButton();
copy=JF_Notpad.changeIconSize(copy, "img/notpad/copy.png", BUTTONWIDTH, BUTTONWIDTH, "Copy");
cut=new JButton();
cut=JF_Notpad.changeIconSize(cut, "img/notpad/cut.png", BUTTONWIDTH, BUTTONWIDTH, "Cut");
paste=new JButton();
paste=JF_Notpad.changeIconSize(unfold, "img/notpad/paste.png", BUTTONWIDTH, BUTTONWIDTH, "Paste");
pasteShortcut=new JButton();
pasteShortcut=JF_Notpad.changeIconSize(pasteShortcut, "img/notpad/pasteShortcut.png", BUTTONWIDTH, BUTTONWIDTH, "PasteShortcut");
delete=new JButton();
delete=JF_Notpad.changeIconSize(delete, "img/notpad/delete.png", BUTTONWIDTH, BUTTONWIDTH, "Delete"); //menuToolBarListener
create.setActionCommand("notpad");
create.addActionListener(this);
unfold.setActionCommand("open");
unfold.addActionListener(this);
copy.setActionCommand("copyE");
copy.addActionListener(this);
cut.setActionCommand("cutE");
cut.addActionListener(this);
paste.setActionCommand("pasteE");
paste.addActionListener(this);
pasteShortcut.setActionCommand("pasteShortcut");
pasteShortcut.addActionListener(this);
delete.setActionCommand("deleteE");
delete.addActionListener(this); //file
newNot=new JMenu("New(N)");
newNot.setMnemonic('N');
ImageIcon icon=new ImageIcon(this.changeImageSize("img/notpad/logo.png", BUTTONWIDTH-5,BUTTONHEIGHT-5 ));
notpad=new JMenuItem("Notpad",icon);
model=new JMenuItem("Model");
icon=new ImageIcon(this.changeImageSize("img/notpad/open.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
open=new JMenuItem("Open",icon);
icon=new ImageIcon(this.changeImageSize("img/notpad/save.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
save=new JMenuItem("Save",icon);
icon=new ImageIcon(this.changeImageSize("img/notpad/saveAs.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
saveAs=new JMenuItem("Save As...",icon);
pageSet=new JMenuItem("PageSet");
print=new JMenuItem("Print");
icon=new ImageIcon(this.changeImageSize("img/notpad/exit.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
exit=new JMenuItem("Exit",icon); //FileListener
notpad.setActionCommand("notpad");
notpad.addActionListener(this);
model.setActionCommand("model");
model.addActionListener(this);
open.setActionCommand("open");
open.addActionListener(this);
save.setActionCommand("save");
save.addActionListener(this);
saveAs.setActionCommand("saveAs");
saveAs.addActionListener(this);
pageSet.setActionCommand("pageSet");
pageSet.addActionListener(this);
print.setActionCommand("print");
print.addActionListener(this);
exit.setActionCommand("exit");
exit.addActionListener(this); //Edit
undoE=new JMenuItem("Undo");
icon=new ImageIcon(this.changeImageSize("img/notpad/cut.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
cutE=new JMenuItem("Cut",icon);
icon=new ImageIcon(this.changeImageSize("img/notpad/copy.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
copyE=new JMenuItem("Copy",icon);
icon=new ImageIcon(this.changeImageSize("img/notpad/paste.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
pasteE=new JMenuItem("Paste",icon);
icon=new ImageIcon(this.changeImageSize("img/notpad/delete.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
deleteE=new JMenuItem("Delete",icon);
findE=new JMenuItem("Find...");
findNextE=new JMenuItem("Find Next");
replaceE=new JMenuItem("Replace...");
goToE=new JMenuItem("Go To..");
selectAllE=new JMenuItem("Select All");
timeDateE=new JMenuItem("Time/Data"); //EditListener
undoE.setActionCommand("undoE");
undoE.addActionListener(this);
cutE.setActionCommand("cutE");
cutE.addActionListener(this);
copyE.setActionCommand("copyE");
copyE.addActionListener(this);
pasteE.setActionCommand("pasteE");
pasteE.addActionListener(this);
deleteE.setActionCommand("deleteE");
deleteE.addActionListener(this);
findE.setActionCommand("findE");
findE.addActionListener(this);
findNextE.setActionCommand("findNextE");
findNextE.addActionListener(this);
replaceE.setActionCommand("replaceE");
replaceE.addActionListener(this);
goToE.setActionCommand("goToE");
goToE.addActionListener(this);
selectAllE.setActionCommand("selectAllE");
selectAllE.addActionListener(this);
timeDateE.setActionCommand("timeDateE");
timeDateE.addActionListener(this); //Format
icon=new ImageIcon(this.changeImageSize("img/notpad/wordWrap.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
wordWrap=new JMenuItem("Word Wrap",icon);
icon=new ImageIcon(this.changeImageSize("img/notpad/font.png", BUTTONWIDTH-8, BUTTONHEIGHT-8));
font=new JMenuItem("Font...",icon); //FormatListener
wordWrap.setActionCommand("wordWrap");
wordWrap.addActionListener(this);
font.setActionCommand("font");
font.addActionListener(this); //View
statusBar=new JMenuItem("Status Bar"); //ViewListener
statusBar.setActionCommand("statusBar");
statusBar.addActionListener(this); //Help
viewHelp=new JMenuItem("View Help");
icon=new ImageIcon(this.changeImageSize("img/notpad/about.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
about=new JMenuItem("About NotePad",icon); //HelpListener
viewHelp.setActionCommand("viewHelp");
viewHelp.addActionListener(this);
about.setActionCommand("about");
about.addActionListener(this); //leftSpace
leftSpace=new JPanel(); //contentFont
contentFont=new Font("KaiTi",Font.PLAIN,20); //textArea
content=new JTextArea();
content.setFont(contentFont);
scroll=new JScrollPane(content);
//scroll.setHorizontalScrollBar(content); //openUrl,saveUrl
// openUrl="E:/notpad.txt";
// saveUrl="E:/notpad.txt";
// saved=false; //saveFilePanel
// Save saveF=new Save("Save",this); //添加组件,从下一级开始装
newNot.add(notpad); newNot.add(model);
file.add(newNot); file.add(open); file.add(save); file.add(saveAs); file.addSeparator(); file.add(pageSet); file.add(print); file.addSeparator(); file.add(exit); edit.add(undoE);
edit.addSeparator();
edit.add(cutE);
edit.add(copyE);
edit.add(pasteE);
edit.add(deleteE);
edit.addSeparator();
edit.add(findE);
edit.add(findNextE);
edit.add(replaceE);
edit.add(goToE);
edit.addSeparator();
edit.add(selectAllE);
edit.add(timeDateE); format.add(wordWrap);
format.add(font); view.add(statusBar); help.add(viewHelp);
help.addSeparator();
help.add(about); mb.add(file); mb.add(edit); mb.add(format); mb.add(view); mb.add(help); tool.add(create);
tool.add(unfold);
tool.add(copy);
tool.add(cut);
tool.add(paste);
tool.add(pasteShortcut);
tool.add(delete); this.setJMenuBar(mb);
this.add(tool,BorderLayout.NORTH);
this.add(leftSpace,BorderLayout.WEST);
this.add(scroll); this.setTitle("Notpad");
this.setIconImage(new ImageIcon("img/notpad/logo.png").getImage());
this.setLocation(300,300);
this.setSize(400,400);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setVisible(true); } private String origContent=null; //保存一开始的文件或者保存过的文件
private String copyContent=null;
@Override
public void actionPerformed(ActionEvent e) {
switch(e.getActionCommand()){
case "notpad":{
System.out.println("notpad"); this.isChangeFile("txt"); }break; case "model":{
System.out.println("model"); this.isChangeFile("java");
}break; case "open":{
System.out.println("open");
//防止第一次打开空文件时,还没保存
if(this.origContent==null){
this.saved=true;
} if(saved){
this.openFilePanel();
}else{
Save saveF=new Save("Save",this);
this.openFilePanel();
} }break; case "save":{
System.out.println("save");
this.saveFile();
//this.setSaved(true); }break; case "saveAs":{
System.out.println("saveAs"); String str=content.getText();
//选择保存文件的路径
JFileChooser fileChoose=null;
if(saveUrl==null){
fileChoose=new JFileChooser();
}else{
fileChoose=new JFileChooser(saveUrl);
}
FileNameExtensionFilter filter=new FileNameExtensionFilter("txt & java","java","txt"); //设置可以识别的文件
fileChoose.setFileFilter(filter);
fileChoose.setDialogTitle("Save File");
fileChoose.showSaveDialog(save);
fileChoose.setVisible(true); File outFile =fileChoose.getSelectedFile();
saveUrl=fileChoose.getSelectedFile().getPath();
PrintStream p=null;
try{
p=new PrintStream(outFile);
System.setOut(p);
System.out.print(str);
}catch(Exception a){
System.out.println("SaveAS File Error!!");
}finally{
p.close();
}
}break; case "pageSet":{
System.out.println("pageSet"); }break; case "print":{
System.out.println("print"); }break; case "exit":{
System.out.println("exit"); System.exit(-1);
}break; case "undoE":{
System.out.println("undoE"); }break; case "cutE":{
System.out.println("cutE");
if(this.content.getSelectedText()!=null){
this.copyContent=this.content.getSelectedText();
}
this.content.replaceSelection("");
}break; case "copyE":{
System.out.println("copyE");
if(this.content.getSelectedText()!=null){
this.copyContent=this.content.getSelectedText();
} }break; case "pasteE":{
System.out.println("pasteE");
if(copyContent!=null){
this.content.replaceRange("", content.getSelectionStart(), content.getSelectionEnd());
}
this.content.insert(copyContent, this.content.getSelectionStart());
}break; case "deleteE":{
System.out.println("deleteE"); this.content.replaceSelection("");
}break; case "findE":{
System.out.println("findE"); }break; case "findNextE":{
System.out.println("findNextE"); }break; case "replaceE":{
System.out.println("replaceE"); }break; case "goToE":{
System.out.println("goToE"); }break; case "selectAllE":{
System.out.println("selectAllE"); this.content.selectAll();
}break; case "timeDateE":{
System.out.println("timeDateE"); SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//System.out.println(df.format(new Date()));
this.content.insert(df.format(new Date()), content.getSelectionStart());
}break; case "wordWrap":{
System.out.println("wordWrap"); ImageIcon icon;
if(this.content.getLineWrap()){
this.content.setLineWrap(false);
icon=new ImageIcon(this.changeImageSize("img/notpad/wordWrap.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
this.wordWrap.setIcon(icon);
}else{
this.content.setLineWrap(true);
icon=new ImageIcon(this.changeImageSize("img/notpad/wordWrapNo.png", BUTTONWIDTH-5, BUTTONHEIGHT-5));
this.wordWrap.setIcon(icon);
} }break; case "font":{
System.out.println("font"); FontPanel f=new FontPanel("Font",this); // this.content.setFont(new Font(f.getFontN(),f.getFontSytleN(),f.getSizeN())); }break; case "statusBar":{
System.out.println("statusBar"); }break; case "viewHelp":{
System.out.println("viewHelp"); }break; case "about":{
System.out.println("about"); About a=new About("About","1.0","feiquan","228332xxxxx@qq.com","xxx-xxxx-xxxx","https://www.baidu.com");
}break; case "pasteShortcut":{
System.out.println("pasteShortcut"); }break; } } @Override
public void windowOpened(WindowEvent e) {
// TODO Auto-generated method stub } @Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.out .println("弹出是否选择保存的对话框");
if(saved){
Save saveF=new Save("Save",this);
}
} @Override
public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub } @Override
public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub } @Override
public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub } @Override
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub } @Override
public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub } public static String getOpenUrl() {
return openUrl;
} public static void setOpenUrl(String openUrl) {
JF_Notpad.openUrl = openUrl;
} public static String getSaveUrl() {
return saveUrl;
} public static void setSaveUrl(String saveUrl) {
JF_Notpad.saveUrl = saveUrl;
} //保存文件其中包含了,判断文件是否存在
public void saveFile(){
String str=this.content.getText();
System.out.println("正在保存:\n"+str); //判断文件是否存在,不存在则创建文件
File file=new File(openUrl);
if(!file.exists()){
try{
file.createNewFile();
}catch(Exception a){
System.out.println("创建文件 "+file.getAbsolutePath()+" 失败!!");
}
} PrintStream p=null;
try{
p=new PrintStream(new File(openUrl));
System.setOut(p);
System.out.print(str);
saved=true;
}catch(Exception a){
System.out.println("Save File Error!!");
saved=false;
}finally{
p.close();
} } //判断文件是否修改过,并根据传入的属性判断新建那个文件
public void isChangeFile(String properties){
System.out.println("是否保存文件:"+saved);
//判断文件是否修改过
if(!(this.content.getText().equals(origContent))){
saved=false;
} //如果内容为空,也视为已经保存
if(this.content.getText()==null||this.content.getText().equals(""))saved=true; System.out.println("判断后是否保存文件:"+saved);
if(saved){
switch(properties){
case "txt":{
this.content.setText("");
this.setTitle("notpad");
origContent="";
}break;
case "java":{
this.setTitle("notpad");
String str="public class Notpad {\n\tpublic static void main (String[] ages) {\n\t\t\n\t}\n}";
this.content.setText(str); origContent=str;
}break;
} }else{
System.out .println("弹出是否选择保存的对话框");
Save saveF=new Save("Save",this); }
System.out.println("经过保存面板后是否保存文件:"+saved);
} //打开选择打开文件面板,并选择文件
public void openFilePanel(){
origContent=this.content.getText();
//显示选择文件面板
JFileChooser fileChoose=null;
if(openUrl==null){
fileChoose=new JFileChooser();
}else{
fileChoose=new JFileChooser(openUrl);
}
FileNameExtensionFilter filter=new FileNameExtensionFilter("txt & java","java","txt");
fileChoose.setFileFilter(filter);
fileChoose.setDialogTitle("Open File");
fileChoose.showOpenDialog(null);
fileChoose.setVisible(true); //得到文件
String url=fileChoose.getSelectedFile().getAbsolutePath(); //得到选择文件的路径 //设置保存面板显示的路径
JF_Notpad.setOpenUrl(url);
Save saveF=new Save("Save",this);
saveF.setVisible(false);
saveF.setUrl(url);
JLabel temp=saveF.getUrlL();
temp.setText(url+" ?");
saveF.setUrlL(temp); String name=fileChoose.getSelectedFile().getName();
this.setTitle(name+" - Notpad"); //设置主窗口标题 //文件流
FileReader fRead=null; BufferedReader buffRead=null; try{
fRead=new FileReader(openUrl);
buffRead=new BufferedReader(fRead); String str=""; String readLine="";
readLine=buffRead.readLine();
while(readLine!=null){
str=str+readLine+"\r\n";
readLine=buffRead.readLine();
} content.setText(str);
origContent=str;
}catch(Exception a){
System.out.println("Open file error!!");
}finally{
try{
fRead.close();
buffRead.close();
}catch(Exception b){
System.out.println("Open file stream error!!");
}
}
} public boolean isSaved() {
return saved;
} public void setSaved(boolean saved) {
this.saved = saved;
} public boolean getOpenFileBool() {
return openFileBool;
} public void setOpenFileBool(boolean openFileBool) {
this.openFileBool = openFileBool;
} public String getOrigContent() {
return origContent;
} public void setOrigContent(String origContent) {
this.origContent = origContent;
} public JTextArea getContent() {
return content;
} public void setContent(JTextArea content) {
this.content = content;
}
}

JF_Notpad.java

  FontPanel.java实现,字体面板:

  

import java.awt.*;
import javax.swing.*;
import java.awt.event.*; public class FontPanel extends JFrame implements ActionListener{
private JList list1,list2,list3;
private JScrollPane scroll1,scroll2,scroll3;
private JLabel l1,l2,l3,l4,l5,l6,simpleL;
private JButton ok,cancel,use;
private JPanel p,scrollP,p2,space,space2,simple,mainP,bottomP;
private static String fontN="KaiTi";
private static int fontSytleN=0,sizeN=20;
private JF_Notpad notpad ; // public static void main (String[] ages) {
// FontPanel f=new FontPanel("Font");
//
// } FontPanel(String title,JF_Notpad notpad){ this.notpad=notpad; String[] s={"Font","FontStyle","Size"}; //获取系统字体
String[] font=GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
String style=" PLAIN,BOLD, ITALIC ";
String[] fontStyle=style.split(",");
String sizeStr="";
for(int i=8;i<73;i++){
sizeStr=sizeStr+i+",";
}
String[] size=sizeStr.split(",");
int count=5; list1=new JList(font);
list1.setVisibleRowCount(count);
list2=new JList(fontStyle);
list2.setVisibleRowCount(count);
list3=new JList(size);
list3.setVisibleRowCount(count); list1.setSelectedIndex(153);
list2.setSelectedIndex(0);
list3.setSelectedIndex(12); scroll1=new JScrollPane(list1);
scroll2=new JScrollPane(list2);
scroll3=new JScrollPane(list3); l1=new JLabel(s[0],JLabel.CENTER);
l2=new JLabel(s[1],JLabel.CENTER);
l3=new JLabel(s[2],JLabel.CENTER);
l4=new JLabel(this.fontN,JLabel.CENTER);
l5=new JLabel(fontStyle[this.fontSytleN],JLabel.CENTER);
l6=new JLabel(String.valueOf(this.sizeN),JLabel.CENTER); ok=new JButton("OK"); cancel=new JButton("Cancel");
ok.setActionCommand("OK"); ok.addActionListener(this);
cancel.setActionCommand("Cancel"); cancel.addActionListener(this); p=new JPanel();
p.setLayout(new GridLayout(2,3,10,10)); p.add(l1); p.add(l2); p.add(l3);
p.add(l4); p.add(l5); p.add(l6); scrollP=new JPanel(new GridLayout(1,3,10,10)); scrollP.add(scroll1); scrollP.add(scroll2); scrollP.add(scroll3); simple=new JPanel();
simple.setLayout(new FlowLayout(FlowLayout.LEFT));
simpleL=new JLabel("AaBbYyZz");
simpleL.setFont(new Font(FontPanel.fontN,FontPanel.fontSytleN,FontPanel.sizeN)); use=new JButton("Simple");
use.setActionCommand("Simple");
use.addActionListener(this); simple.add(use); simple.add(new JLabel(" ")); simple.add(simpleL); p2=new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT)); p2.add(ok); p2.add(cancel); space=new JPanel();
space2=new JPanel(); bottomP=new JPanel(new GridLayout(2,1,10,10));
bottomP.add(simple); bottomP.add(p2); mainP =new JPanel(new GridLayout(3,1,10,10)); mainP.add(p); mainP.add(scrollP); mainP.add(bottomP); this.add(mainP);
this.add(p2,BorderLayout.SOUTH);
this.add(space,BorderLayout.WEST);
this.add(space2,BorderLayout.EAST); this.setTitle(title);
this.setIconImage(new ImageIcon("img/notpad/font.png").getImage());
this.setLocation(300,300);
this.setSize(500,640);
this.setVisible(true);
this.setResizable(false);
// this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); } @Override
public void actionPerformed(ActionEvent e) {
switch(e.getActionCommand()){
case "OK":{
this.setFontN(this.list1.getSelectedValue().toString());
this.setFontSytleN(this.list2.getSelectedIndex());
this.setSizeN(this.list3.getSelectedIndex()+8);
// System.out.println(this.getFontN()+"\t"+this.getFontSytleN()+"\t"+this.getSizeN());
this.setVisible(false); Font f=new Font(FontPanel.fontN,FontPanel.fontSytleN,FontPanel.sizeN);
JTextArea t=notpad.getContent();
t.setFont(f);
notpad.setContent(t);
}break;
case "Cancel":{
this.setVisible(false);
}break;
case "Simple":{
this.simpleL.setFont(new Font(this.list1.getSelectedValue().toString(),this.list2.getSelectedIndex(),this.list3.getSelectedIndex()+8));
}break;
}
} public static String getFontN() {
return fontN;
} public static void setFontN(String fontN) {
FontPanel.fontN = fontN;
} public static int getFontSytleN() {
return fontSytleN;
} public static void setFontSytleN(int fontSytleN) {
FontPanel.fontSytleN = fontSytleN;
} public static int getSizeN() {
return sizeN;
} public static void setSizeN(int sizeN) {
FontPanel.sizeN = sizeN;
}
}

FontPanel.java

  About.java实现关于面板: 

import java.awt.*;
import javax.swing.*;
import java.awt.event.*; public class About extends JFrame implements ActionListener {
private JLabel [] l={null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
private JPanel p,p2;
private JButton b; About(String title,String version,String copyrigth,String qqEmil,String relative,String href){
String [] s={"","","Version:",version," "," ","@CopyRight:",copyrigth,"QQ邮箱:",qqEmil,"联系方式:",relative,"","<html><a href='"+href+"'>更多</a></html>>","",""};
JPanel p=new JPanel();
p.setLayout(new GridLayout((int)l.length/2,2));
for(int i=0;i<l.length;i++){
if(i%2==0){
l[i]=new JLabel(s[i],JLabel.CENTER);
}else{
l[i]=new JLabel(s[i],JLabel.LEFT) ;
}
//设置手型
if(i==13){
l[i].setCursor(Cursor.getDefaultCursor().getPredefinedCursor(Cursor.HAND_CURSOR));
}
p.add(l[i]);
}
System.out.println(l.length);
b=new JButton("OK");
b.setActionCommand("OK");
b.addActionListener(this); p2=new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
p2.add(b);
p2.add(new JLabel(" ")); this.add(p);
this.add(p2,BorderLayout.SOUTH);
this.setTitle(title);
this.setIconImage(new ImageIcon("img/notpad/about.png").getImage());
this.setLocation(300,300);
this.setSize(350,300);
this.setVisible(true);
this.setResizable(false);
//this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
} public void actionPerformed(ActionEvent e)
{
System.out.println(e);
}
}

About.java

    Save.java实现文件的保存读取:

  

import java.awt.*;
import java.awt.event.*;
import javax.swing.*; public class Save extends JFrame implements ActionListener {
private JLabel l,urlL;
private JButton save,noSave,cancel;
private String url;
private JPanel bottomP,contentP;
private Font font;
private JF_Notpad notpad; // public static void main(String[] ages){
// Save s=new Save("Save");
// } Save(String title,JF_Notpad notpad){
this.notpad=notpad; font=new Font("",Font.BOLD,14); url=notpad.getOpenUrl()+" ?";
urlL=new JLabel(url,JLabel.CENTER);
urlL.setFont(font);
l=new JLabel("Do you want to save changes to ",JLabel.CENTER);
l.setFont(font); contentP=new JPanel(new GridLayout(2,1));
contentP.add(l); contentP.add(urlL); save=new JButton("Save");
noSave=new JButton("Don't Save");
cancel=new JButton("Cancel"); save.setActionCommand("Save");
noSave.setActionCommand("noSave");
cancel.setActionCommand("Cancel"); save.addActionListener(this);
noSave.addActionListener(this);
cancel.addActionListener(this); bottomP=new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomP.add(save); bottomP.add(noSave); bottomP.add(cancel); this.add(contentP);
this.add(bottomP,BorderLayout.SOUTH); this.setTitle(title);
this.setLocation(300,300);
this.setSize(400,170);
this.setResizable(false);
// this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setVisible(true); } @Override
public void actionPerformed(ActionEvent e) {
switch(e.getActionCommand()){
case "Save":{
notpad.saveFile();
notpad.setSaved(true);
notpad.setOrigContent(notpad.getContent().getText());
this.setVisible(false); }break;
case "noSave":{
notpad.setOrigContent(notpad.getContent().getText());
notpad.setSaved(true);
this.setVisible(false);
}break;
case "Cancel":{
notpad.setSaved(false);
this.setVisible(false);
}break;
}
} public String getUrl() {
return url;
} public void setUrl(String url) {
this.url = url;
} public JLabel getUrlL() {
return urlL;
} public void setUrlL(JLabel urlL) {
this.urlL = urlL;
}
}

Save.java

版权

作者:feiquan

出处:http://www.cnblogs.com/feiquan/

版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

大家写文都不容易,请尊重劳动成果~ 这里谢谢大家啦(*/ω\*)

  

java实现Windows记事本的更多相关文章

  1. 签名、BOM头、编码、Windows记事本编码、java编码解码的那些事

    对于Windows记事本: ANSI :GB2312 java中应使用GBK解码 Unicode :有签名的UTF-16LE java中应使用UTF-16解码 Unicode big endian : ...

  2. 编写运行最简单的java程序——使用记事本编写java程序

    第一个java程序--使用记事本编辑 经过上篇文章的java环境搭建成功的小伙伴们可以在自己的计算机上编写属于自己的java程序了yo~ 还没有搭建环境变量的小伙伴请转移到上一篇的随笔中去完成搭建. ...

  3. Windows 记事本的 ANSI、Unicode、UTF-8 这三种编码模式有什么区别?

    [梁海的回答(99票)]: 简答.一些细节暂无精力查证,如果说错了还请指出. 一句话建议:涉及兼容性考量时,不要用记事本,用专业的文本编辑器保存为不带 BOM 的UTF-8. * * * 如果是为了跨 ...

  4. java 调用windows bat脚本

    当我们需要在java程序中调用外部程序,我们可用通过Runtime.exec()调用来完成. The class java.lang.Runtime features a static method ...

  5. 使用Java修改Windows注册表

    使用Java修改Windows注册表,使用最基本的就是cmd命令. 事例和运行结果如下所示: package day01; import java.io.IOException; /* 1,reg a ...

  6. Java 修改Windows注册表,以实现开机自启动应用程序。

    使用Java修改Windows注册表,使用最基本的就是cmd命令. 事例和运行结果如下所示: package day01; import java.io.IOException; /* 1,reg a ...

  7. Selenium2学习-001-Selenium2 WebUI自动化Java开发 Windows 环境配置

    此文主要介绍 Selenium2 WebUI自动化Java开发 Windows 环境配置,供各位亲们参考,若有不足之处,敬请各位大神指正,非常感谢! 所需软件列表如下所示: 所属分类 具体名称 备注 ...

  8. Java读写Windows共享文件夹 .

    版权声明:本文为博主原创文章,未经博主允许不得转载. 项目常常需要有访问共享文件夹的需求,例如共享文件夹存储照片.文件等.那么如何使用Java读写Windows共享文件夹呢? Java可以使用JCIF ...

  9. Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例【附详细代码】

    http://blog.csdn.net/xiefu5hh/article/details/51707529 Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例[附 ...

随机推荐

  1. 主机名变成bogon?连不上mysql?你需要看下这篇文章

    通过navicat for mysql操作部署在虚拟机centos里面的mysql数据库时候总是出现类似于下面的提示信息: Can't connct to MySQL server on '*.*.* ...

  2. HttpClientFactory与Steeltoe结合来完成服务发现

    前言 上一篇说了一下用HttpClientFactory实现了简单的熔断降级. 这篇就来简单说说用HttpClientFactory来实现服务发现.由于标题已经好明显的说了Steeltoe 因此这里会 ...

  3. 【朝花夕拾】Lint使用篇

    工作中Lint工具使用实录及整理       AndroidStudio内置的Lint工具,对app中的代码规范带来了极大的方便.对内存泄漏.代码冗余.代码安全.国际化.代码规范等很多方面都能检测,是 ...

  4. Android--从系统Gallery获取图片

    前言 在Android应用中,经常有场景会需要使用到设备上存储的图片,而直接从路径中获取无疑是非常不便利的.所以一般推荐调用系统的Gallery应用,选择图片,然后使用它.本篇博客将讲解如何在Andr ...

  5. 【Android】打开本地的html文件

    网上好多说法 但实际上说到点上的没有 不想写太长 直接进入正题 Intent intent = new Intent(Intent.ACTION_VIEW); intent.addCategory(I ...

  6. Mongodb~Linux环境下的部署~服务的部署与自动化

    <mongodb在linux上的部署> 事实上redis安装程序挺好,直接帮我们生成了服务,直接可以使用systemctl去启动它,而mongodb在这方面没有那么智能,需要我们去编写自己 ...

  7. (1)Maven快速入门_1maven安装

    Maven 快速入门 1.1 Maven官网下载     windows 系统 下载 下图红色框选处. 下载到本地解压, 创建一个本地maven仓库的目录 maven_lib 配置Maven的环境变量 ...

  8. java的ArrayList源码摘要

    ArrayList本质上是一组对象数组,ArrayList有三种构造方法 1.指定长度创建ArrayList,2.默认长度为10创建.3,用旧的集合创建一个ArrayList. 对ArrayList的 ...

  9. 微信公众平台设置URL和Token接收接口事件推送

    最近做对接微信闪开发票-微信发票名片,里面有个接收用户提交抬头接口是微信推送事件到公众号后台,该事件将发送至开发者填写的URL(登录公众平台进入[开发者中心设置]). 开发者可通过事件推送完成数据统计 ...

  10. 多线程(3)ThreadPool

    使用Thread类已经可以创建并启动线程了,但是随着开启的线程越来越多,线程的创建和终止都需要手动操作,非常繁琐,另一个问题是,开启更多新的线程但是没有用的线程没有及时得到终止的时候,会占用越来越多的 ...