1、打開(kāi)需要編輯的記事本文件。
創(chuàng)新互聯(lián)長(zhǎng)期為上1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為新密企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站,新密網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
2、在需要?jiǎng)h除的內(nèi)容前面點(diǎn)一下鼠標(biāo)左鍵,然后安裝不松,拖動(dòng)鼠標(biāo)到需要?jiǎng)h除內(nèi)容的終止位置,松開(kāi)鼠標(biāo)左鍵,如果需要大面積選擇,可以先選擇起始行,然后按住鍵盤上的Shift鍵不松,拖動(dòng)文件右側(cè)滾動(dòng)條到終止位置,點(diǎn)一下鼠標(biāo)左鍵,即可選中。
3、右鍵點(diǎn)選中的內(nèi)容選擇刪除,或者按鍵盤上的Backspace鍵刪除。
4、修改完畢,點(diǎn)文件,選擇保存或者按CTRL+S保存即可。
public class NotePad extends JFrame implements ActionListener, ItemListener {
boolean haveCreated = false;
File file = null;
String strtext = "";
int findIndex = 0;
String findStr;
JMenuBar menubar = new JMenuBar();
JMenu meFile = new JMenu(" 文件 ");
JMenu meEdit = new JMenu(" 編輯 ");
JMenu meStyle = new JMenu(" 風(fēng)格 ");
JMenu meHelp = new JMenu(" 幫助 ");
JMenuItem miCreate = new JMenuItem(" 新建 ");
JMenuItem miOpen = new JMenuItem(" 打開(kāi) ");
JMenuItem miSave = new JMenuItem(" 保存 ");
JMenuItem miSaveAs = new JMenuItem(" 另存為 ");
JMenuItem miExit = new JMenuItem(" 退出 ");
JMenuItem miUndo = new JMenuItem(" 撤消 ");
JMenuItem miCut = new JMenuItem(" 剪切 ");
JMenuItem miCopy = new JMenuItem(" 復(fù)制 ");
JMenuItem miPaste = new JMenuItem(" 粘貼 ");
JMenuItem miDelete = new JMenuItem(" 刪除 ");
JMenuItem miFind = new JMenuItem(" 查找 ");
JMenuItem miNext = new JMenuItem(" 查找下一個(gè) ");
JMenuItem miReplace = new JMenuItem(" 替換 ");
// 右鍵彈出菜單項(xiàng)
JMenuItem pmUndo = new JMenuItem(" 撤消 ");
JMenuItem pmCut = new JMenuItem(" 剪切 ");
JMenuItem pmCopy = new JMenuItem(" 復(fù)制 ");
JMenuItem pmPaste = new JMenuItem(" 粘貼 ");
JMenuItem pmDelete = new JMenuItem(" 刪除 ");
JCheckBoxMenuItem miNewLine = new JCheckBoxMenuItem(" 自動(dòng)換行 ");
JMenu smLookFeel = new JMenu(" 觀感 ");
JMenuItem metal = new JMenuItem(" Metal ");
JMenuItem motif = new JMenuItem(" Motif ");
JMenuItem windows = new JMenuItem(" Windows ");
JMenuItem miAbout = new JMenuItem(" 關(guān)于 ");
JPopupMenu popupMenu;
JTextArea text = new JTextArea();
public NotePad() {
super(" 我的記事本 ");
// 為便于區(qū)分事件源,設(shè)定名字
miCreate.setActionCommand(" create ");
miOpen.setActionCommand(" open ");
miSave.setActionCommand(" save ");
miSaveAs.setActionCommand(" saveAs ");
miExit.setActionCommand(" exit ");
miUndo.setActionCommand(" undo ");
miCut.setActionCommand(" cut ");
miCopy.setActionCommand(" copy ");
miPaste.setActionCommand(" paste ");
miDelete.setActionCommand(" delete ");
miFind.setActionCommand(" find ");
miNext.setActionCommand(" next ");
miReplace.setActionCommand(" replace ");
miNewLine.setActionCommand(" newLine ");
miAbout.setActionCommand(" about ");
pmUndo.setActionCommand(" undo ");
pmCut.setActionCommand(" cut ");
pmCopy.setActionCommand(" copy ");
pmPaste.setActionCommand(" paste ");
pmDelete.setActionCommand(" delete ");
this.setSize(500, 500);
this.setLocation(300, 150);
this.setJMenuBar(menubar);
meFile.setFont(new Font(" 宋體 ", Font.BOLD, 15));
meEdit.setFont(new Font(" 宋體 ", Font.BOLD, 15));
meStyle.setFont(new Font(" 宋體 ", Font.BOLD, 15));
meHelp.setFont(new Font(" 宋體 ", Font.BOLD, 15));
menubar.add(meFile);
menubar.add(meEdit);
menubar.add(meStyle);
menubar.add(meHelp);
meFile.add(miCreate);
meFile.add(miOpen);
meFile.add(miSave);
meFile.add(miSaveAs);
meFile.addSeparator();
meFile.add(miExit);
meEdit.add(miUndo);
meEdit.addSeparator();
meEdit.add(miCut);
meEdit.add(miCopy);
meEdit.add(miPaste);
meEdit.add(miDelete);
meEdit.addSeparator();
meEdit.add(miFind);
meEdit.add(miNext);
meEdit.addSeparator();
meEdit.add(miReplace);
meStyle.add(miNewLine);
meStyle.add(smLookFeel);
smLookFeel.add(metal);
smLookFeel.add(motif);
smLookFeel.add(windows);
meHelp.add(miAbout);
// 添加到右鍵彈出菜單
popupMenu = new JPopupMenu();
popupMenu.add(pmUndo);
popupMenu.addSeparator();
popupMenu.add(pmCut);
popupMenu.add(pmCopy);
popupMenu.add(pmPaste);
popupMenu.add(pmDelete);
// 添加按鈕事件監(jiān)聽(tīng)
meHelp.addActionListener(this);
miCreate.addActionListener(this);
miOpen.addActionListener(this);
miSave.addActionListener(this);
miSaveAs.addActionListener(this);
miExit.addActionListener(this);
miUndo.addActionListener(this);
miCut.addActionListener(this);
miCopy.addActionListener(this);
miPaste.addActionListener(this);
miDelete.addActionListener(this);
miFind.addActionListener(this);
miNext.addActionListener(this);
miReplace.addActionListener(this);
miNewLine.addItemListener(this);
miAbout.addActionListener(this);
metal.addActionListener(this);
motif.addActionListener(this);
windows.addActionListener(this);
// 添加右鍵按鈕事件監(jiān)聽(tīng)器
pmUndo.addActionListener(this);
pmCut.addActionListener(this);
pmCopy.addActionListener(this);
pmPaste.addActionListener(this);
pmDelete.addActionListener(this);
// 文本區(qū)內(nèi)容沒(méi)有選中時(shí)某些按鈕不可用
miCut.setEnabled(false);
miCopy.setEnabled(false);
miDelete.setEnabled(false);
pmCut.setEnabled(false);
pmCopy.setEnabled(false);
pmDelete.setEnabled(false);
JScrollPane scrollPane = new JScrollPane(text);
getContentPane().add(scrollPane, BorderLayout.CENTER);
text.setFont(new Font(" Fixedsys ", Font.TRUETYPE_FONT, 15));
setVisible(true);
// 添加鍵盤輸入監(jiān)聽(tīng)器
text.addFocusListener(new MyFocusAdapter());
// 添加鼠標(biāo)監(jiān)聽(tīng)器,用于激活右鍵彈出菜單
text.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
});
以下代碼是一個(gè)完整的實(shí)現(xiàn),你只要復(fù)制過(guò)去就可以了~~
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import javax.swing.text.*;
public class Start
{
public static void main(String args[])
{
new TextPad();
}
}
class TextPad extends JFrame implements ActionListener
{
JTextArea jta=new JTextArea("小廖記事本:)",18,52);
JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自動(dòng)換行",true);
String ss1=jta.getText();
UndoableEditListener ue=new UndoHander();
UndoManager undo = new UndoManager();
int StartFindPos=0,a=0,b=0;
GridBagConstraints gbc=new GridBagConstraints();
//Dimension dd=new Dimension();
// jta.getDocument().addUndoableEditListener(ue);
public TextPad()
{
//MyMenuListener ml=new MyMenuListener();
//JTextArea jta=new JTextArea("This is my textpad",18,52);
//System.out.println(dd.getHeight());
//System.out.println(dd.getWidth());
//System.out.println(this.getHeight());
//System.out.println(this.getWidth());
//System.out.println("OK");
this.setTitle("一個(gè)功能比較齊全的JAVA記事本");
this.setLocation(180,100);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
JPanel jp=new JPanel();
JScrollPane jsp=new JScrollPane(jta);
jp.add(jsp);
//Rectangle rt=new Rectangle(0,0,this.getWidth(),this.getHeight());
//jsp.setBounds(rt);
//System.out.println(this.getHeight());
//System.out.println(this.getWidth());
JMenu mf=new JMenu("文件(F)");
JMenuItem mtf1=new JMenuItem("新建");
mtf1.addActionListener(this);
JMenuItem mtf2=new JMenuItem("打開(kāi)");
//mtf2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));
mtf2.addActionListener(this);
JMenuItem mtf3=new JMenuItem("保存");
//mtf3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
mtf3.addActionListener(this);
JMenuItem mtf4=new JMenuItem("另存為");
mtf4.addActionListener(this);
JMenuItem mtf5=new JMenuItem("退出");
mtf5.addActionListener(this);
JMenu me=new JMenu("編輯(E)");
JMenuItem mte1=new JMenuItem("撤消");
mte1.addActionListener(this);
jta.getDocument().addUndoableEditListener(ue);
if(undo.canUndo())
{
mte1.setEnabled(false);
}
JMenuItem mte2=new JMenuItem("剪切");
mte2.addActionListener(this);
JMenuItem mte3=new JMenuItem("復(fù)制");
mte3.addActionListener(this);
JMenuItem mte4=new JMenuItem("粘貼");
mte4.addActionListener(this);
//JMenuItem mte5=new JMenuItem("刪除");
//mte5.addActionListener(this);
JMenuItem mte6=new JMenuItem("查找");
mte6.addActionListener(this);
//JMenuItem mte7=new JMenuItem("查找下一個(gè)");
JMenuItem mte8=new JMenuItem("替換");
mte8.addActionListener(this);
//JMenuItem mte9=new JMenuItem("轉(zhuǎn)到");
JMenuItem mte10=new JMenuItem("全選");
mte10.addActionListener(this);
JMenuItem mte11=new JMenuItem("日期/時(shí)間");
mte11.addActionListener(this);
JMenu mo=new JMenu("格式(O)");
//JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自動(dòng)換行(W)");
mto1.addActionListener(this);
JMenuItem mto2=new JMenuItem("字體");
mto2.addActionListener(this);
JMenu mv=new JMenu("查看(V)");
JMenuItem mtv1=new JMenuItem("狀態(tài)欄");
mtv1.setEnabled(false);
JMenu mh=new JMenu("幫助(H)");
JMenuItem mth1=new JMenuItem("關(guān)于記事本");
mth1.addActionListener(this);
JMenuBar mb=new JMenuBar();
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
mb.add(mf);
mb.add(me);
mb.add(mo);
mb.add(mv);
mb.add(mh);
this.setJMenuBar(mb);
mf.add(mtf1);
mf.add(mtf2);
mf.add(mtf3);
mf.add(mtf4);
mf.addSeparator();
mf.add(mtf5);
me.add(mte1);
me.addSeparator();
me.add(mte2);
me.add(mte3);
me.add(mte4);
//me.add(mte5);
me.addSeparator();
me.add(mte6);
//me.add(mte7);
me.add(mte8);
//me.add(mte9);
me.addSeparator();
me.add(mte10);
me.add(mte11);
mo.add(mto1);
mo.add(mto2);
mv.add(mtv1);
mh.add(mth1);
this.getContentPane().add(jsp);
this.setSize(600,400);
this.setResizable(true);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("打開(kāi)"))
{
try
{
Frame f=new Frame();
FileDialog fd=new FileDialog(f,"打開(kāi)文件",FileDialog.LOAD);
fd.setVisible(true);
String fpath=fd.getDirectory();
String fname=fd.getFile();
BufferedReader br=new BufferedReader(new FileReader(fpath+fname));
jta.setText("");
String s=br.readLine();
while(s!=null)
{
jta.append(s+"\n");
s=br.readLine();
}
br.close();
}
catch(Exception ex)
{
}
}
if(e.getActionCommand().equals("保存"))
{
String fns=null;
Frame f=new Frame("保存");
FileDialog fd=new FileDialog(f,"保存文件",FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);
try
{
String savepath=fd.getDirectory();
String savename=fd.getFile();
if(savename!=null)
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));
pw.write(jta.getText(),0,jta.getText().length());
pw.flush();
}
}
catch(Exception esave)
{
}
}
if(e.getActionCommand().equals("新建"))
{
jta.setText("");
}
if(e.getActionCommand().equals("另存為"))
{
Frame f=new Frame("保存");
FileDialog fd=new FileDialog(f,"文件另存為",FileDialog.SAVE);
fd.setVisible(true);
try
{
String savepath=fd.getDirectory();
String savename=fd.getFile();
if(savename!=null)
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));
pw.write(jta.getText(),0,jta.getText().length());
pw.flush();
}
}
catch(Exception esave)
{
}
}
if(e.getActionCommand().equals("退出"))
{
String ss2=jta.getText();
if(!ss1.equals(ss2))
{
System.out.println("File is changed.");
}
System.exit(0);
}
if(e.getActionCommand().equals("撤消"))
{
try
{
undo.undo();
//System.out.println(undo.canUndo());
}
catch(Exception eundo)
{
}
}
if(e.getActionCommand().equals("剪切"))
{
jta.cut();
}
if(e.getActionCommand().equals("復(fù)制"))
{
jta.copy();
}
if(e.getActionCommand().equals("粘貼"))
{
jta.paste();
}
if(e.getActionCommand().equals("刪除"))
{
}
if(e.getActionCommand().equals("全選"))
{
jta.selectAll();
}
if(e.getActionCommand().equals("查找"))
{
try
{
final JDialog jd=new JDialog(this,"查找",true);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.weightx=0.5;
gbc.weighty=0.5;
gbc.gridwidth=1;
gbc.gridheight=1;
jd.getContentPane().setLayout(gbl);
jd.setSize(380,100);
jd.setResizable(false);
//jd.setDefaultLookAndFeelDecorated(true);
final JTextField jtf=new JTextField(15);
JLabel jlFind=new JLabel("查找內(nèi)容:");
jd.getContentPane().add(jlFind);
JButton jbFind=new JButton("查找");
jbFind.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent efind)
{
String strA=jta.getText();
String strB=jtf.getText();
if(a=0)
{
a=strA.indexOf(strB,StartFindPos);
b=strB.length();
StartFindPos=a+b;
if(a==-1)
{
JOptionPane.showMessageDialog(null, "沒(méi)有您要查找的信息", "查找結(jié)果",1);
a=0;
StartFindPos=0;
}
jta.select(a,StartFindPos);
}
}
}
);
JButton jbCancel=new JButton("取消");
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.getContentPane().add(jtf);
jd.getContentPane().add(jbFind);
jd.getContentPane().add(jbCancel);
//jd.setResizable(false);
jd.setLocation(240,200);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jd.setVisible(true);
}
catch(Exception efind)
{
}
}
if(e.getActionCommand().equals("替換"))
{
final JDialog jd=new JDialog(this,"替換",true);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.weightx=1;
gbc.weighty=1;
gbc.gridwidth=1;
gbc.gridheight=1;
JLabel jlFind=new JLabel("查找:");
JLabel jp=new JLabel("替換內(nèi)容:");
final JTextField jtf=new JTextField(15);
final JTextField jtf1=new JTextField(15);
jd.getContentPane().setLayout(gbl);
jd.setSize(330,150);
jd.setResizable(false);
final JButton jbReplace=new JButton("替換");
final JButton jbReplaceAll=new JButton("替換所有");
final JButton jbCancel=new JButton("取消");
final JButton jbFind=new JButton("查找");
gbc.gridx=0;
gbc.gridy=0;
jd.getContentPane().add(jlFind,gbc);
gbc.gridx=1;
gbc.gridy=0;
jd.getContentPane().add(jtf1,gbc);
gbc.gridx=2;
gbc.gridy=0;
jd.getContentPane().add(jbFind,gbc);
gbc.gridx=0;
gbc.gridy=1;
jd.getContentPane().add(jp,gbc);
gbc.gridx=1;
gbc.gridy=1;
jd.getContentPane().add(jtf,gbc);
gbc.gridx=2;
gbc.gridy=1;
jd.getContentPane().add(jbReplace,gbc);
gbc.gridx=2;
gbc.gridy=2;
jd.getContentPane().add(jbReplaceAll,gbc);
gbc.gridx=2;
gbc.gridy=3;
jd.getContentPane().add(jbCancel,gbc);
jbFind.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent efind)
{
String strA=jta.getText();
String strB=jtf1.getText();
if(a=0)
{
a=strA.indexOf(strB,StartFindPos);
//System.out.println(a+b);
b=strB.length();
StartFindPos=a+b;
if(a==-1)
{
JOptionPane.showMessageDialog(null, "沒(méi)有您要查找的信息", "查找結(jié)果",1);
a=0;
StartFindPos=0;
}
jta.select(a,StartFindPos);
//System.out.println(StartFindPos);
}
}
}
);
jbReplace.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("替換"))
{
String strRepleace=jtf.getText();
jta.replaceSelection(strRepleace);
}
}
}
);
jbReplaceAll.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
while(a-1)
{
String strA=jta.getText();
String strB=jtf1.getText();
a=strA.indexOf(strB,StartFindPos);
if(a==-1)
{
break;
}
//System.out.println(a+b);
b=strB.length();
StartFindPos=a+b;
//System.out.println(StartFindPos);
jta.select(a,StartFindPos);
//System.out.println(StartFindPos);
String strRepleaceAll=jtf.getText();
jta.replaceSelection(strRepleaceAll);
StartFindPos=a+b;
}
JOptionPane.showMessageDialog(null, "全部替換完畢", "替換內(nèi)容",1);
a=0;
StartFindPos=0;
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.setLocation(240,200);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("日期/時(shí)間"))
{
final JDialog jd=new JDialog(this,"插入日期");
JPanel jp1=new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.LEFT));
final JTextField jtf=new JTextField(10);
JButton jbOK=new JButton("確定");
JButton jbCancel=new JButton("取消");
//Calendar cl=Calendar.getInstance();
//DateFormat df=DateFormat.getInstance();
//String sdate1=df.format(cl.getTime());
//jtf.setText(sdate1);
jp1.add(jtf);
jp1.add(jbOK);
jp1.add(jbCancel);
jd.getContentPane().add(jp1,"North");
JPanel jp2=new JPanel();
jp2.setLayout(new FlowLayout(FlowLayout.LEFT));
final JCheckBox jcb1=new JCheckBox("格式一");
final JCheckBox jcb2=new JCheckBox("格式二");
final JCheckBox jcb3=new JCheckBox("格式三");
jp2.add(jcb1);
jp2.add(jcb2);
jp2.add(jcb3);
jd.getContentPane().add(jp2,"Center");
jd.setSize(220,120);
jd.setResizable(false);
jd.setLocation(240,200);
final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Calendar cl=Calendar.getInstance();
DateFormat df=DateFormat.getInstance();
final String sdate=df.format(cl.getTime());
jcb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式一"))
{
if(jcb1.isSelected())
{
try
{
SimpleDateFormat sdf1=new SimpleDateFormat("yy年MM月dd日");
Date d=sdf.parse(sdate);
jtf.setText(sdf1.format(d));
jcb2.setEnabled(false);
jcb3.setEnabled(false);
}
catch(Exception estyle1)
{
estyle1.printStackTrace();
}
}
else
{
jcb2.setEnabled(true);
jcb3.setEnabled(true);
}
try
{
System.out.println(jta.getLineStartOffset(3));
//System.out.println(jta.getLineOfOffset(346));
}
catch(Exception eee)
{
}
}
}
}
);
jcb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式二"))
{
if(jcb2.isSelected())
{
try
{
SimpleDateFormat sdf1=new SimpleDateFormat("yy/MM/dd");
Date d=sdf.parse(sdate);
jtf.setText(sdf1.format(d));
jcb1.setEnabled(false);
jcb3.setEnabled(false);
}
catch(Exception estyle2)
{
estyle2.printStackTrace();
}
}
else
{
jcb1.setEnabled(true);
jcb3.setEnabled(true);
}
//System.out.println(jcb1.isSelected());
}
}
}
);
jcb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式三"))
{
if(jcb3.isSelected())
{
jtf.setText(sdate);
jcb1.setEnabled(false);
jcb2.setEnabled(false);
}
else
{
jcb1.setEnabled(true);
jcb2.setEnabled(true);
}
//System.out.println(jcb1.isSelected());
}
}
}
);
jbOK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("確定"))
{
int pos=jta.getCaretPosition();
jta.insert(jtf.getText(),pos);
}
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("自動(dòng)換行"))
{
if(mto1.getState())
{
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
}
else
{
jta.setLineWrap(false);
jta.setWrapStyleWord(false);
}
//System.out.println("OK");
}
if(e.getActionCommand().equals("字體"))
{
final JDialog jd=new JDialog(this,"字體設(shè)置");
jd.setLocation(240,200);
//final JFrame jfontview=new JFrame();
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
JButton jbOK=new JButton("確定");
JButton jbCancel=new JButton("取消");
JTextField jtf1=new JTextField(6);
final JTextArea jtaview=new JTextArea(4,8);
//jfontview.getContentPane().add(jtaview);
final JTextField jtf2=new JTextField(6);
final JTextField jtf3=new JTextField(3);
JComboBox jcb1=new JComboBox();
final JComboBox jcb2=new JComboBox();
jcb2.addItem("BOLD");
jcb2.addItem("ITALIC");
jcb2.addItem("PLAIN");
//jcb2.addItem("BOLDITALIC");
jcb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf2.setText((String)jcb2.getSelectedItem());
}
}
);
final JComboBox jcb3=new JComboBox();
jcb3.addItem("14");
jcb3.addItem("18");
jcb3.addItem("22");
jcb3.addItem("26");
jcb3.addItem("30");
jcb3.addItem("34");
jcb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf3.setText((String)jcb3.getSelectedItem());
//jtaview.setText("SS");
// int fontsizeview=Integer.parseInt((String)jcb3.getSelectedItem());
//Font fontview=new Font("字體預(yù)覽",Font.BOLD,fontsizeview);
//jtaview.setFont(fontview);
//jtaview.setEditable(false);
}
}
);
gbc.gridheight=1;
gbc.gridwidth=1;
//gbc.gridx=1;
//gbc.gridy=0;
gbc.weightx=0.5;
gbc.weighty=0.5;
jd.getContentPane().setLayout(gbl);
//JLabel jl1=new JLabel("預(yù)覽:");
JLabel jl2=new JLabel("字型:");
JLabel jl3=new JLabel("大小:");
gbc.gridx=0;
gbc.gridy=0;
jd.getContentPane().add(jl2,gbc);
gbc.gridx=2;
gbc.gridy=0;
jd.getContentPane().add(jl3,gbc);
//gbc.gridx=4;
//gbc.gridy=0;
//jd.getContentPane().add(jl3,gbc);
gbc.gridx=0;
gbc.gridy=1;
jd.getContentPane().add(jtf2,gbc);
gbc.gridx=2;
gbc.gridy=1;
jd.getContentPane().add(jtf3,gbc);
//gbc.gridx=4;
// gbc.gridy=1;
//jd.getContentPane().add(jtf3,gbc);
gbc.gridx=0;
gbc.gridy=2;
jd.getContentPane().add(jcb2,gbc);
gbc.gridx=2;
gbc.gridy=2;
jd.getContentPane().add(jcb3,gbc);
//gbc.gridx=4;
//gbc.gridy=2;
//jd.getContentPane().add(jcb3,gbc);
gbc.gridx=4;
gbc.gridy=1;
jd.getContentPane().add(jbOK,gbc);
gbc.gridx=4;
gbc.gridy=2;
jd.getContentPane().add(jbCancel,gbc);
jbOK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(jtf2.getText().equals("PLAIN"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=0;
Font f=new Font("字體設(shè)置",fontstyle,fontsize);
jta.setFont(f);
// System.out.println(f.getFont("楷體_GB2312").getFontName());
}
if(jtf2.getText().equals("BOLD"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=1;
Font f=new Font("字體設(shè)置",fontstyle,fontsize);
jta.setFont(f);
}
if(jtf2.getText().equals("ITALIC"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=2;
Font f=new Font("字體設(shè)置",fontstyle,fontsize);
jta.setFont(f);
}
jd.dispose();
//System.out.println(fontstyle);
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jd.dispose();
}
}
);
jd.setSize(200,120);
jd.setResizable(false);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("關(guān)于記事本"))
{
JOptionPane jop=new JOptionPane(null,JOptionPane.INFORMATION_MESSAGE);
jop.showMessageDialog(null,"小廖記事本","關(guān)于記事本",JOptionPane.OK_OPTION);
//System.out.println("OK");
}
}
class UndoHander implements UndoableEditListener
{
public void undoableEditHappened(UndoableEditEvent eundo)
{
undo.addEdit(eundo.getEdit());
}
}
}
你說(shuō)的不就是一個(gè)記事本嗎,
//import java packages
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import java.io.*;
import javax.swing.undo.*;
import javax.swing.border.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import java.awt.datatransfer.*;
public class Notepad extends JFrame implements ActionListener,DocumentListener{
//定義變量
//菜單
JMenu fileMenu,editMenu,formatMenu,viewMenu,helpMenu;
//"文件"的菜單項(xiàng)
JMenuItem fileMenu_New,fileMenu_Open,fileMenu_Save,fileMenu_SaveAs,fileMenu_PageSetup,fileMenu_Print,fileMenu_Exit;
//"編輯"的菜單項(xiàng)
JMenuItem editMenu_Undo,editMenu_Redo,editMenu_Cut,editMenu_Copy,editMenu_Paste,editMenu_Delete,editMenu_Find,editMenu_FindNext,editMenu_Replace,
editMenu_GoTo,editMenu_SelectAll,editMenu_TimeDate;
//"格式"的菜單項(xiàng)
JCheckBoxMenuItem formatMenu_LineWrap;
JMenu formatMenu_Color;
JMenuItem formatMenu_Font,formatMenu_Color_FgColor,formatMenu_Color_BgColor;
//"查看"的菜單項(xiàng)
JCheckBoxMenuItem viewMenu_Status;
//"幫助"的菜單項(xiàng)
JMenuItem helpMenu_HelpTopics,helpMenu_About;
//文本編輯區(qū)域
JTextArea editArea;
//狀態(tài)欄標(biāo)簽
JLabel statusLabel;
//彈出菜單及菜單項(xiàng)
JPopupMenu popupMenu;
JMenuItem popupMenu_Undo,popupMenu_Redo,popupMenu_Cut,popupMenu_Copy,popupMenu_Paste,popupMenu_Delete,popupMenu_SelectAll;
//系統(tǒng)剪貼板
Toolkit toolKit=Toolkit.getDefaultToolkit();
Clipboard clipBoard=toolKit.getSystemClipboard();
//其它變量
boolean isNewFile=true; //是否新文件(未保存過(guò)的)
File currentFile; //當(dāng)前文件名
String oldValue; //存放編輯區(qū)原來(lái)的內(nèi)容,用于比較文本是否有改動(dòng)
JButton fontOkButton; //字體設(shè)置里的"確定"按鈕
//工具欄按鈕
JButton newButton,openButton,saveButton,saveAsButton,printButton,undoButton,redoButton,
cutButton,copyButton,pasteButton,deleteButton,searchButton,timeButton,fontButton,
boldButton,italicButton,fgcolorButton,bgcolorButton,helpButton;
//創(chuàng)建撤消操作管理器
protected UndoManager undo = new UndoManager();
protected UndoableEditListener undoHandler = new UndoHandler();
//設(shè)置編輯區(qū)默認(rèn)字體
protected Font defaultFont=new Font("宋體",Font.PLAIN,12);
//構(gòu)造函數(shù)開(kāi)始
public Notepad()
{
super("黃斌的記事本");
//獲取容器
Container container=getContentPane();
//創(chuàng)建菜單條
JMenuBar menuBar = new JMenuBar();
//創(chuàng)建文件菜單及菜單項(xiàng)并注冊(cè)事件監(jiān)聽(tīng)
JMenu fileMenu = new JMenu("文件(F)", true);
fileMenu.setMnemonic('F');
fileMenu_New = new JMenuItem("新建(N)", 'N');
fileMenu_New.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
fileMenu_New.addActionListener(this);
fileMenu_Open = new JMenuItem("打開(kāi)(O)...", 'O');
fileMenu_Open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
fileMenu_Open.addActionListener(this);
fileMenu_Save = new JMenuItem("保存(S)", 'S');
fileMenu_Save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
fileMenu_Save.addActionListener(this);
fileMenu_SaveAs = new JMenuItem("另存為(A)...", 'A');
fileMenu_SaveAs.addActionListener(this);
fileMenu_PageSetup = new JMenuItem("頁(yè)面設(shè)置(U)...",'U');
fileMenu_PageSetup.addActionListener(this);
fileMenu_Print = new JMenuItem("打印(P)...", 'P');
fileMenu_Print.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK));
fileMenu_Print.addActionListener(this);
fileMenu_Exit = new JMenuItem("退出(X)",'X');
fileMenu_Exit.addActionListener(this);
//創(chuàng)建編輯菜單及菜單項(xiàng)并注冊(cè)事件監(jiān)聽(tīng)
JMenu editMenu = new JMenu("編輯(E)", true);
editMenu.setMnemonic('E');
editMenu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
checkMenuItemEnabled();//設(shè)置剪切、復(fù)制、粘貼、刪除等功能的可用性
}
}
);
editMenu_Undo = new JMenuItem("撤消(U)",'U');
editMenu_Undo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK));
editMenu_Undo.addActionListener(this);
editMenu_Undo.setEnabled(false);
editMenu_Redo = new JMenuItem("重做(R)",'R');
editMenu_Redo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y,InputEvent.CTRL_MASK));
editMenu_Redo.addActionListener(this);
editMenu_Redo.setEnabled(false);
editMenu_Cut = new JMenuItem("剪切(T)",'T');
editMenu_Cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
editMenu_Cut.addActionListener(this);
editMenu_Copy = new JMenuItem("復(fù)制(C)",'C');
editMenu_Copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
editMenu_Copy.addActionListener(this);
editMenu_Paste = new JMenuItem("粘貼(P)",'P');
editMenu_Paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));
editMenu_Paste.addActionListener(this);
editMenu_Delete = new JMenuItem("刪除(L)",'L');
editMenu_Delete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
editMenu_Delete.addActionListener(this);
editMenu_Find = new JMenuItem("查找(F)...",'F');
editMenu_Find.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
editMenu_Find.addActionListener(this);
editMenu_FindNext = new JMenuItem("查找下一個(gè)(N)",'N');
editMenu_FindNext.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3,0));
editMenu_FindNext.addActionListener(this);
editMenu_Replace = new JMenuItem("替換(R)...",'R');
editMenu_Replace.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_MASK));
editMenu_Replace.addActionListener(this);
editMenu_GoTo = new JMenuItem("轉(zhuǎn)到(G)...",'G');
editMenu_GoTo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK));
editMenu_GoTo.addActionListener(this);
editMenu_SelectAll = new JMenuItem("全選",'A');
editMenu_SelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
editMenu_SelectAll.addActionListener(this);
editMenu_TimeDate = new JMenuItem("時(shí)間/日期(D)",'D');
editMenu_TimeDate.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5,0));
editMenu_TimeDate.addActionListener(this);
//創(chuàng)建格式菜單及菜單項(xiàng)并注冊(cè)事件監(jiān)聽(tīng)
JMenu formatMenu = new JMenu("格式(O)", true);
formatMenu.setMnemonic('O');
formatMenu_LineWrap = new JCheckBoxMenuItem("自動(dòng)換行(W)");
formatMenu_LineWrap.setMnemonic('W');
formatMenu_LineWrap.setState(true);
formatMenu_LineWrap.addActionListener(this);
formatMenu_Font = new JMenuItem("字體(F)...",'F');
formatMenu_Font.addActionListener(this);
formatMenu_Color = new JMenu("設(shè)置顏色");
formatMenu_Color_FgColor=new JMenuItem("字體顏色");
formatMenu_Color_FgColor.addActionListener(this);
formatMenu_Color_BgColor=new JMenuItem("背景顏色");
formatMenu_Color_BgColor.addActionListener(this);
//創(chuàng)建查看菜單及菜單項(xiàng)并注冊(cè)事件監(jiān)聽(tīng)
JMenu viewMenu = new JMenu("查看(V)", true);
viewMenu.setMnemonic('V');
viewMenu_Status = new JCheckBoxMenuItem("狀態(tài)欄(S)");
viewMenu_Status.setMnemonic('S');
viewMenu_Status.setState(true);
viewMenu_Status.addActionListener(this);
//創(chuàng)建幫助菜單及菜單項(xiàng)并注冊(cè)事件監(jiān)聽(tīng)
JMenu helpMenu = new JMenu("幫助(H)", true);
helpMenu.setMnemonic('H');
helpMenu_HelpTopics = new JMenuItem("幫助主題(H)",'H');
helpMenu_HelpTopics.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,0));
helpMenu_HelpTopics.addActionListener(this);
helpMenu_About = new JMenuItem("關(guān)于記事本(A)",'A');
helpMenu_About.addActionListener(this);
//向菜單條添加"文件"菜單及菜單項(xiàng)
menuBar.add(fileMenu);
fileMenu.add(fileMenu_New);
fileMenu.add(fileMenu_Open);
fileMenu.add(fileMenu_Save);
fileMenu.add(fileMenu_SaveAs);
fileMenu.addSeparator(); //分隔線
fileMenu.add(fileMenu_PageSetup);
fileMenu.add(fileMenu_Print);
fileMenu.addSeparator(); //分隔線
fileMenu.add(fileMenu_Exit);
//向菜單條添加"編輯"菜單及菜單項(xiàng)
menuBar.add(editMenu);
editMenu.add(editMenu_Undo);
editMenu.add(editMenu_Redo);
editMenu.addSeparator(); //分隔線
editMenu.add(editMenu_Cut);
editMenu.add(editMenu_Copy);
editMenu.add(editMenu_Paste);
editMenu.add(editMenu_Delete);
editMenu.addSeparator(); //分隔線
editMenu.add(editMenu_Find);
editMenu.add(editMenu_FindNext);
editMenu.add(editMenu_Replace);
editMenu.add(editMenu_GoTo);
editMenu.addSeparator(); //分隔線
editMenu.add(editMenu_SelectAll);
editMenu.add(editMenu_TimeDate);
//向菜單條添加"格式"菜單及菜單項(xiàng)
menuBar.add(formatMenu);
formatMenu.add(formatMenu_LineWrap);
formatMenu.add(formatMenu_Font);
formatMenu.addSeparator();
formatMenu.add(formatMenu_Color);
formatMenu_Color.add(formatMenu_Color_FgColor);
formatMenu_Color.add(formatMenu_Color_BgColor);
//向菜單條添加"查看"菜單及菜單項(xiàng)
menuBar.add(viewMenu);
viewMenu.add(viewMenu_Status);
//向菜單條添加"幫助"菜單及菜單項(xiàng)
menuBar.add(helpMenu);
helpMenu.add(helpMenu_HelpTopics);
helpMenu.addSeparator();
helpMenu.add(helpMenu_About);
//向窗口添加菜單條
this.setJMenuBar(menuBar);
//創(chuàng)建文本編輯區(qū)并添加滾動(dòng)條
editArea=new JTextArea(20,50);
JScrollPane scroller=new JScrollPane(editArea);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
container.add(scroller,BorderLayout.CENTER);//向容器添加文本編輯區(qū)
editArea.setWrapStyleWord(true); //設(shè)置單詞在一行不足容納時(shí)換行
editArea.setLineWrap(true); //設(shè)置文本編輯區(qū)自動(dòng)換行默認(rèn)為true,即會(huì)"自動(dòng)換行"
editArea.setFont(defaultFont); //設(shè)置編輯區(qū)默認(rèn)字體
editArea.setBackground(Color.white); //設(shè)置編輯區(qū)默認(rèn)背景色
editArea.setForeground(Color.black); //設(shè)置編輯區(qū)默認(rèn)前景色
oldValue=editArea.getText(); //獲取原文本編輯區(qū)的內(nèi)容
//編輯區(qū)注冊(cè)事件監(jiān)聽(tīng)
editArea.getDocument().addUndoableEditListener(undoHandler);
editArea.getDocument().addDocumentListener(this);
//創(chuàng)建右鍵彈出菜單
popupMenu=new JPopupMenu();
popupMenu_Undo=new JMenuItem("撤消(U)",'U');
popupMenu_Redo=new JMenuItem("重做(R)",'R');
popupMenu_Cut =new JMenuItem("剪切(T)",'T');
popupMenu_Copy=new JMenuItem("復(fù)制(C)",'C');
popupMenu_Paste=new JMenuItem("粘貼(P)",'P');
popupMenu_Delete=new JMenuItem("刪除(D)",'D');
popupMenu_SelectAll=new JMenuItem("全選(A)",'A');
popupMenu_Undo.setEnabled(false); //撤消選項(xiàng)初始設(shè)為不可用
popupMenu_Redo.setEnabled(false); //重做選項(xiàng)初始設(shè)為不可用
//向右鍵菜單添加菜單項(xiàng)和分隔符
popupMenu.add(popupMenu_Undo);
popupMenu.add(popupMenu_Redo);
popupMenu.addSeparator();
popupMenu.add(popupMenu_Cut);
popupMenu.add(popupMenu_Copy);
popupMenu.add(popupMenu_Paste);
popupMenu.add(popupMenu_Delete);
popupMenu.addSeparator();
popupMenu.add(popupMenu_SelectAll);
//右鍵菜單注冊(cè)事件
popupMenu_Undo.addActionListener(this);
popupMenu_Redo.addActionListener(this);
popupMenu_Cut.addActionListener(this);
popupMenu_Copy.addActionListener(this);
popupMenu_Paste.addActionListener(this);
popupMenu_Delete.addActionListener(this);
popupMenu_SelectAll.addActionListener(this);
//文本編輯區(qū)注冊(cè)右鍵菜單事件
editArea.addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent e)
{
checkForTriggerEvent(e);
}
public void mouseReleased(MouseEvent e)
{
checkForTriggerEvent(e);
}
private void checkForTriggerEvent(MouseEvent e)
{
if(e.isPopupTrigger())
popupMenu.show(e.getComponent(),e.getX(),e.getY());
checkMenuItemEnabled(); //設(shè)置剪切、復(fù)制、粘貼、刪除等功能的可用性
editArea.requestFocus(); //編輯區(qū)獲取焦點(diǎn)
}
});
//創(chuàng)建工具欄
JPanel toolBar=new JPanel();
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
Icon newIcon=new ImageIcon("Icons/new.gif");
Icon openIcon=new ImageIcon("Icons/open.gif");
Icon saveIcon=new ImageIcon("Icons/save.gif");
Icon saveAsIcon=new ImageIcon("Icons/saveas.gif");
Icon printIcon=new ImageIcon("Icons/print.gif");
Icon undoIcon=new ImageIcon("Icons/undo.gif");
Icon redoIcon=new ImageIcon("Icons/redo.gif");
Icon cutIcon=new ImageIcon("Icons/cut.gif");
Icon copyIcon=new ImageIcon("Icons/copy.gif");
Icon pasteIcon=new ImageIcon("Icons/paste.gif");
Icon deleteIcon=new ImageIcon("Icons/delete.gif");
Icon searchIcon=new ImageIcon("Icons/search.gif");
Icon timeIcon=new ImageIcon("Icons/time.gif");
Icon fontIcon=new ImageIcon("Icons/font.gif");
Icon boldIcon=new ImageIcon("Icons/bold.gif");
Icon italicIcon=new ImageIcon("Icons/italic.gif");
Icon bgcolorIcon=new ImageIcon("Icons/bgcolor.gif");
Icon fgcolorIcon=new ImageIcon("Icons/fgcolor.gif");
Icon helpIcon=new ImageIcon("Icons/help.gif");
newButton= new JButton(newIcon);
openButton=new JButton(openIcon);
saveButton= new JButton(saveIcon);
saveAsButton=new JButton(saveAsIcon);
printButton=new JButton(printIcon);
undoButton=new JButton(undoIcon);
undoButton.setEnabled(false);
redoButton=new JButton(redoIcon);
redoButton.setEnabled(false);
cutButton=new JButton(cutIcon);
cutButton.setEnabled(false);
copyButton=new JButton(copyIcon);
copyButton.setEnabled(false);
pasteButton=new JButton(pasteIcon);
pasteButton.setEnabled(false);
deleteButton=new JButton(deleteIcon);
deleteButton.setEnabled(false);
searchButton=new JButton(searchIcon);
timeButton=new JButton(timeIcon);
fontButton=new JButton(fontIcon);
boldButton=new JButton(boldIcon);
italicButton=new JButton(italicIcon);
fgcolorButton=new JButton(fgcolorIcon);
bgcolorButton=new JButton(bgcolorIcon);
helpButton=new JButton(helpIcon);
newButton.setPreferredSize(new Dimension(22,22));
openButton.setPreferredSize(new Dimension(22,22));
saveButton.setPreferredSize(new Dimension(22,22));
saveAsButton.setPreferredSize(new Dimension(22,22));
printButton.setPreferredSize(new Dimension(22,22));
undoButton.setPreferredSize(new Dimension(22,22));
redoButton.setPreferredSize(new Dimension(22,22));
cutButton.setPreferredSize(new Dimension(22,22));
copyButton.setPreferredSize(new Dimension(22,22));
pasteButton.setPreferredSize(new Dimension(22,22));
deleteButton.setPreferredSize(new Dimension(22,22));
searchButton.setPreferredSize(new Dimension(22,22));
timeButton.setPreferredSize(new Dimension(22,22));
fontButton.setPreferredSize(new Dimension(22,22));
boldButton.setPreferredSize(new Dimension(22,22));
italicButton.setPreferredSize(new Dimension(22,22));
fgcolorButton.setPreferredSize(new Dimension(22,22));
bgcolorButton.setPreferredSize(new Dimension(22,22));
helpButton.setPreferredSize(new Dimension(22,22));
//注冊(cè)工具欄按鈕事件
newButton.addActionListener(this);
openButton.addActionListener(this);
saveButton.addActionListener(this);
saveAsButton.addActionListener(this);
printButton.addActionListener(this);
undoButton.addActionListener(this);
redoButton.addActionListener(this);
cutButton.addActionListener(this);
copyButton.addActionListener(this);
pasteButton.addActionListener(this);
deleteButton.addActionListener(this);
searchButton.addActionListener(this);
timeButton.addActionListener(this);
fontButton.addActionListener(this);
boldButton.addActionListener(this);
italicButton.addActionListener(this);
fgcolorButton.addActionListener(this);
bgcolorButton.addActionListener(this);
helpButton.addActionListener(this);
分享題目:Java記事本代碼刪除 java記事本編輯的文件要保存在哪里
網(wǎng)站網(wǎng)址:http://jinyejixie.com/article18/ddcdhgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、品牌網(wǎng)站制作、移動(dòng)網(wǎng)站建設(shè)、微信公眾號(hào)、自適應(yīng)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)