⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.java

📁 java小例子大家瞎看一下吧
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class example extends Frame implements ActionListener,WindowListener
{
 Frame f;
 Frame F;
 //我这里参照java书 141 142页程序段
 MenuBar m=new MenuBar( );
 Menu m1=new Menu("文件");
 Menu m2=new Menu("背景");
 Menu m3=new Menu("帮助");
 Menu m4=new Menu("字体");
 Menu m5=new Menu("字颜色");
 MenuItem M1=new MenuItem("打开");
 MenuItem M2=new MenuItem("保存");
 MenuItem M3=new MenuItem("退出");
 MenuItem M4=new MenuItem("粉");
 MenuItem M5=new MenuItem("黄");
 MenuItem M6=new MenuItem("关于..");
 MenuItem M7=new MenuItem("新建");
 MenuItem M8=new MenuItem("常规");
 MenuItem M9=new MenuItem("黑体");
 MenuItem M10=new MenuItem("斜体");
 MenuItem M11=new MenuItem("放大黑体");
 MenuItem M13=new MenuItem("红");
 MenuItem M14=new MenuItem("橙");
 MenuItem M15=new MenuItem("蓝");
 MenuItem M16=new MenuItem("绿");
 TextArea t=new TextArea(5,30);
 Dialog d;
 String  s2="简介\n"
            +"欢迎进入记事本,\n"
            +"可以对文本进行编辑关闭以及为了满足不同的用户,选择不同的字体大小和背景颜色\n"
            +"谢谢使用\n";
 String s3="";
 Font f1=new Font("Dialog",Font.PLAIN,20);
 Font f2=new Font("TimesRoman",Font.BOLD,30);
 Font f3=new Font("Courier",Font.ITALIC,38);
 Font f4=new Font("DialogInput",Font.PLAIN,80);
public void go()
{ m.add(m1);
  m.add(m4);
  m.add(m5);
  m.add(m2);
  m.add(m3);
  m1.add(M7); 
  m1.add(M1);
  m1.add(M2);
  m1.add(M3); 
  m2.add(M4);
  m2.add(M5);
  m3.add(M6); 
  m4.add(M8);
  m4.add(M9);
  m4.add(M10);
  m4.add(M11);
  m5.add(M13);
  m5.add(M14);
  m5.add(M15);
  m5.add(M16);
  setMenuBar(m); 
  add(t);
  m1.addActionListener(this);
  m2.addActionListener(this);
  m3.addActionListener(this);
  m4.addActionListener(this);
  m5.addActionListener(this);
  F=new Frame();
  setSize(450,500);
  //我这里参照java书 138 139页程序段
  d=new Dialog(F,"Dialog",true);
  d.add("Center",new Label("确实退出文件吗?"));
  d.pack();
  d.addWindowListener(this);
 }
public void actionPerformed(ActionEvent e)
 {   f=new Frame();
    if(e.getActionCommand()=="新建")
      { t.setText(s3);
        t.setBackground(Color.white);
      }
 //我这里参照java书 140 141 145页程序段     
    else if(e.getActionCommand()=="打开")
    {FileDialog fd1=new FileDialog(f,"打开文件",0);
     fd1.show();
     t.setText("Directory:       "+fd1.getDirectory());
     t.append("\nFilename: "+fd1.getFile());
     }
   else if(e.getActionCommand()=="保存")
    {FileDialog fd2=new FileDialog(f,"保存文件",1);
     fd2.show();
     }
   else if(e.getActionCommand()=="退出")
    {d.setVisible(true);
     System.exit(0);
     }
//我这里参照java书 149页程序段
    else if(e.getActionCommand()=="常规")
     { t.setFont(f1);}
    else if(e.getActionCommand()=="黑体")
     {t.setFont(f2);}
    else if(e.getActionCommand()=="斜体")
     {t.setFont(f3);}
    else if(e.getActionCommand()=="放大黑体")
     {t.setFont(f4);}
     else if(e.getActionCommand()=="红")
      {t.setForeground(Color.red);}
     else if(e.getActionCommand()=="橙")
      {t.setForeground(Color.orange);}
     else if(e.getActionCommand()=="蓝")
      {t.setForeground(Color.blue);}
     else if(e.getActionCommand()=="绿")
      {t.setForeground(Color.green);}    
    else if(e.getActionCommand()=="粉")
    {
     t.setBackground(Color.pink);
     }
    else if(e.getActionCommand()=="黄")
    {
       t.setBackground(Color.yellow);
    } 
  
    else if(e.getActionCommand()=="关于..")
    {
      t.setText(s2);
    }
 }
public void windowClosing(WindowEvent e)
{d.setVisible(false);}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public static void main(String args[])
  {example e=new example();
   e.go();
   e.setVisible(true);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -