文本编辑器,您不妨试试哟!
程序员文章站
2022-07-12 20:28:36
...
文本编辑器
package xioa;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class MyTextEdit extends Frame implements ActionListener,ItemListener,MouseListener {
TextArea text;
String str="";
CheckboxMenuItem miFontBold,miFontItalic;
PopupMenu popM;
int style=Font.PLAIN;
public MyTextEdit(String s)
{
super(s);
addWindowListener(new WindowAdapter()
{
public void windowClosing (WindowEvent e)
{
dispose();
System.exit(0);
}
});
Menu mn1=new Menu("文件");
MenuItem miOpen=new MenuItem("打开",new MenuShortcut(KeyEvent.VK_O));
MenuItem miNew=new MenuItem("新建",new MenuShortcut(KeyEvent.VK_N));
MenuItem miSave=new MenuItem("保存",new MenuShortcut(KeyEvent.VK_S));
MenuItem miSaveAs=new MenuItem("另寸为",new MenuShortcut(KeyEvent.VK_A));
MenuItem miClose=new MenuItem("关闭",new MenuShortcut(KeyEvent.VK_C));
mn1.add(miOpen);
mn1.add(miNew);
mn1.addSeparator();
mn1.add(miSave);
mn1.add(miSaveAs);
mn1.addSeparator();
mn1.add(miClose);
miOpen.addActionListener(this);
miNew.addActionListener(this);
miSave.addActionListener(this);
miSaveAs.addActionListener(this);
miClose.addActionListener(this);
Menu mn2=new Menu("编辑 ");
MenuItem miCopy=new MenuItem("复制",new MenuShortcut(KeyEvent.VK_O));
MenuItem miPaste=new MenuItem("粘贴",new MenuShortcut(KeyEvent.VK_O));
MenuItem miFind=new MenuItem("查找",new MenuShortcut(KeyEvent.VK_O));
MenuItem miReplase=new MenuItem("替换",new MenuShortcut(KeyEvent.VK_O));
mn2.add(miCopy);
mn2.add(miPaste);
mn2.addSeparator();
mn2.add(miFind);
mn2.add(miReplase);
miCopy.addActionListener(this);
miPaste.addActionListener(this);
miFind.addActionListener(this);
miReplase.addActionListener(this);
mn2.addSeparator();
Menu miFont=new Menu("字体");
CheckboxMenuItem miFontBold=new CheckboxMenuItem("黑体");
CheckboxMenuItem miFontItalic=new CheckboxMenuItem("斜体");
CheckboxMenuItem miFontFontItalic=new CheckboxMenuItem("下画线");
miFont.add(miFontBold);
miFont.add(miFontItalic);
miFont.add(miFontBold);
miFontBold.addItemListener(this);
miFontItalic.addItemListener(this);
miFontBold.addItemListener(this);
mn2.add(miFont);
MenuBar mb=new MenuBar();
mb.add(mn1);
mb.add(mn2);
setMenuBar(mb);
popM=new PopupMenu();
text=new TextArea();
text.add(popM);
text.addMouseListener(this);
add(text,BorderLayout.CENTER);
setSize(500,400);
setVisible(true);
}
@ Override
public void mouseClicked(MouseEvent e){
//TODO Auto-generated method stub
}
@ Override
public void mousePressed(MouseEvent e){
//TODO Auto-generated method stub
}
@ Override
public void mouseReleased(MouseEvent e){
//TODO Auto-generated method stub
}
@ Override
public void mouseEntered(MouseEvent e){
//TODO Auto-generated method stub
}
@ Override
public void mouseExited(MouseEvent e){
//TODO Auto-generated method stub
}
@ Override
public void itemStateChanged(ItemEvent e){
//TODO Auto-generated method stub
}
@ Override
public void actionPerformed(ActionEvent e){
//TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
MyTextEdit textEdit=new MyTextEdit("文本编辑器");
}
}
运行结果:
上一篇: 安装Spring Boot CLI
下一篇: vim文本编辑器
推荐阅读