- //MyFrame.java
- package abc.jdm;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.border.Border;
- public class MyFrame extends Frame
- {
- //局部变量的作用域仅限制在方法内.
- static JTextArea mytext=new JTextArea();
- public MyFrame()
- {
- //设置框架窗体标题
- //super(strTitle);
- Toolkit tk=Toolkit.getDefaultToolkit();
- Image image=tk.createImage("M"); /*image.gif是你的图标*/
- this.setIconImage(image);
- //创建菜单条并加入到框架窗体中
- MenuBar mnuMenuBar=new MenuBar();
- this.setMenuBar( mnuMenuBar );
- //设置为默认的工具栏.
- //创建File菜单和相应的菜单项
- Menu mnuFile= new Menu("文件");
- MenuItem filenew=new MenuItem ("新建");
- MenuItem fileopen=new MenuItem ("打开…");
- MenuItem filesave=new MenuItem ("保存");
- filenew.addActionListener(new newfile());
- filesave.addActionListener(new savefile());
- fileopen.addActionListener(new openfile());
- MenuItem fileprint=new MenuItem ("打印");
- MenuItem mnuFileQuit=new MenuItem ("退出");
- mnuFileQuit.addActionListener(new quitframe());
- fileprint.addActionListener(new printframe());
- //把菜单项加入到File菜单中
- mnuFile.add(filenew);
- // mnuFile.addSeparator();//添加分割条
- mnuFile.add(fileopen);
- //mnuFile.addSeparator();//添加分割条
- mnuFile.add(filesave);
- //mnuFile.addSeparator();//添加分割条
- mnuFile.add(fileprint);
- //mnuFile.addSeparator();//添加分割条
- mnuFile.add(mnuFileQuit);
- //创建Edit菜单和相关菜单项并加入到Edit菜单中
- Menu mnuEdit=new Menu("编辑");
- MenuItem cast=new MenuItem("剪切"),copy=new MenuItem("复制"),paste=new MenuItem("粘贴"),all=new MenuItem("全选");
- mnuEdit.add(all);
- mnuEdit.add(cast);
- mnuEdit.add(copy);
- mnuEdit.add(paste);
- copy.addActionListener(new all());
- cast.addActionListener(new all());
- paste.addActionListener(new all());
- //创建Search菜单和相关菜单项并加入到Search菜单中
- Menu mnuSearch=new Menu("搜索");
- MenuItem search=new MenuItem("查找..."),searchnext=new MenuItem("查找下一个"),replace=new MenuItem("替换...");
- mnuSearch.add(search);
- mnuSearch.add(searchnext);
- mnuSearch.add(replace);
- search.addActionListener(new display());
- Menu view=new Menu("格式");
- MenuItem fontitem=new MenuItem("字体"),coloritem=new MenuItem("颜色");
- view.add(fontitem);
- view.add(coloritem);
- coloritem.addActionListener(new colorset());
- //创建Help菜单和相关菜单项并加入到Help菜单中
- Menu mnuHelp=new Menu("帮助");
- MenuItem about=new MenuItem("关于") ;
- MenuItem osinfo=new MenuItem("系统信息") ;
- mnuHelp.add(about);
- mnuHelp.add(osinfo);
- about.addActionListener(new about());
- osinfo.addActionListener(new osinfo());
- //把所有菜单加入到菜单条中
- mnuMenuBar.add( mnuFile );
- mnuFile.addSeparator();//添加分割条
- mnuMenuBar.add( mnuEdit );
- mnuMenuBar.add(view);
- mnuFile.addSeparator();//添加分割条
- mnuMenuBar.add( mnuSearch );
- mnuMenuBar.add( mnuHelp );
- JFrame f=new JFrame("文本编辑器");
- f.setMenuBar(mnuMenuBar);
- f.add(mytext);
- f.setSize(1024,768);
- f.setLocation(120, 50);
- f.setVisible(true);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- //设置框架窗体的大小为宽400,高为400
- /*public Dimension getPreferredSize()
- {
- return new Dimension(800,400);
- }*/
- public String gettext(){
- return mytext.getText();
- }
- public MyFrame(int a){
- gettext();
- }
- //程序的入口方法
- public static void main( String[] args )
- {
- //创建框架窗体
- new start();
- //设置框架窗体的事件监听(关闭窗体事件)
- //显示框架窗体
- }
- }
java 记事本本源代码.
最新推荐文章于 2023-07-28 23:22:33 发布