文本编辑器,您不妨试试哟!

文本编辑器

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("文本编辑器");

    }

}

运行结果:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值