• 记事本


      1 package Com.TomAwt;
      2 
      3 
      4 import java.awt.BorderLayout;
      5 import java.awt.Button;
      6 import java.awt.Color;
      7 import java.awt.Frame;
      8 import java.awt.event.AdjustmentListener;
      9 import java.awt.event.WindowAdapter;
     10 import java.awt.event.WindowEvent;
     11 import java.applet.Applet;
     12 import java.awt.*;
     13 import java.awt.Label;
     14 import java.awt.Panel;
     15 import java.awt.Scrollbar;
     16 import java.awt.event.*;
     17 
     18 
     19 
     20 public class TomAwt_01 extends Frame {
     21     
     22     //frame主窗口 
     23     public  TomAwt_01(){
     24            super("小记事本");
     25            this.setSize(600, 400);
     26            this.setBackground(Color.white);
     27            this.setBounds(100, 100, 600, 500);
     28            this.setVisible(true); 
     29            this.setResizable(false);
     30            
     31            
     32            final MenuBar menuBar = new MenuBar();
     33             
     34               Menu fileMenu = new Menu("File");
     35               Menu editMenu = new Menu("Edit"); 
     36               final Menu aboutMenu = new Menu("About");
     37               
     38               
     39               MenuItem openMenuItem = new MenuItem("Open");
     40               openMenuItem.setActionCommand("Open");
     41 
     42               MenuItem saveMenuItem = new MenuItem("Save");
     43               saveMenuItem.setActionCommand("Save");
     44 
     45               MenuItem exitMenuItem = new MenuItem("Exit");
     46               exitMenuItem.setActionCommand("Exit");
     47 
     48               MenuItem cutMenuItem = new MenuItem("Cut");
     49               cutMenuItem.setActionCommand("Cut");
     50 
     51               MenuItem copyMenuItem = new MenuItem("Copy");
     52               copyMenuItem.setActionCommand("Copy");
     53 
     54               MenuItem pasteMenuItem = new MenuItem("Paste");
     55               pasteMenuItem.setActionCommand("Paste");
     56               
     57               final CheckboxMenuItem showWindowMenu = 
     58                          new CheckboxMenuItem("Show About", true);
     59                       showWindowMenu.addItemListener(new ItemListener() {
     60                          public void itemStateChanged(ItemEvent e) {
     61                             if(showWindowMenu.getState()){
     62                                menuBar.add(aboutMenu);
     63                             }else{
     64                                menuBar.remove(aboutMenu);
     65                             }
     66                          }
     67                       });
     68              
     69 
     70            
     71               
     72               fileMenu.add(openMenuItem);
     73               fileMenu.add(saveMenuItem);
     74               fileMenu.add(exitMenuItem);
     75               fileMenu.add(cutMenuItem);
     76               fileMenu.add(pasteMenuItem);
     77               
     78               menuBar.add(fileMenu);
     79               menuBar.add(editMenu);
     80               menuBar.add(aboutMenu);
     81               
     82               this.setMenuBar(menuBar);
     83           
     84      }
     85     public void init(){
     86         
     87         Panel p1=new Panel();
     88         Panel p2=new Panel();
     89         Panel p3=new Panel();
     90         Panel p4=new Panel();
     91         Panel p5=new Panel();
     92         
     93         //用来设置用户界面上的屏幕组件的格式布局
     94         setLayout(new BorderLayout());
     95         
     96     
     97         
     98         p1.setBackground(Color.black);
     99         p2.setBackground(Color.blue);
    100         p3.setBackground(Color.green);
    101         p4.setBackground(Color.gray);
    102         p5.setBackground(Color.orange);
    103         
    104         add(p1,BorderLayout.NORTH);
    105         add(p2,BorderLayout.SOUTH);
    106         add(p3,BorderLayout.CENTER);
    107         add(p4,BorderLayout.WEST);
    108         //add(p5,BorderLayout.EAST);
    109         
    110         p1.setBackground(Color.black);
    111         p1.setLayout(null);
    112         p1.setLocation(0, 0);
    113         p1.setSize(20, 20);
    114         Label input=new Label();
    115         input.setText("Please input:");
    116         input.setAlignment(input.LEFT);
    117         input.setFont(new java.awt.Font("Dialog", 1, 12));
    118         input.setForeground(Color.white);
    119         //input.setBounds(10, 15, 1, 5);
    120         input.setLocation(10, 0);
    121         input.setSize(90,20);
    122         input.setBackground(Color.GRAY);
    123         p1.add(input);
    124           
    125           
    126           //p1.add(menuBar);    
    127           
    128         p2.setBackground(Color.blue);
    129         Label l=new Label();
    130         l.setText("Welcome to notebook");
    131         //l.setAlignment(l.CENTER);
    132         l.setFont(new java.awt.Font("Dialog", 1, 15));
    133         l.setForeground(Color.white);
    134         l.setBackground(Color.GRAY);
    135         p2.add(l);
    136         
    137         p3.setBackground(Color.green);
    138         TextArea t=new TextArea(23,70);
    139         t.setEditable(true);
    140         t.setVisible(true);
    141         //t.setBounds(10, 10, 600, 500);
    142         p3.add(t);
    143         
    144         p4.setBackground(Color.gray);
    145         p4.setLayout(null);
    146         p4.setLocation(0, 0);
    147         p4.setSize(50,200);
    148         Label num=new Label();
    149         num.setSize(15,10);
    150         num.setLocation(10, 00);
    151         num.setBackground(Color.cyan);
    152         num.setText("00");
    153         
    154         p4.add(num);
    155         //num.setText("2");
    156         p4.add(num);
    157         Label num1=new Label();
    158         Label num2=new Label();
    159         Label num3=new Label();
    160         Label num4=new Label();
    161         Label num5=new Label();
    162         Label num6=new Label();
    163         Label num7=new Label();
    164         Label num8=new Label();
    165         Label num9=new Label();
    166         Label num10=new Label();
    167         Label num11=new Label();
    168         
    169         num1.setSize(15,10);
    170         num2.setSize(15,10);
    171         num3.setSize(15,10);
    172         num4.setSize(15,10);
    173         num5.setSize(15,10);
    174         num6.setSize(15,10);
    175         num7.setSize(15,10);
    176         num8.setSize(15,10);
    177         num9.setSize(15,10);
    178         num10.setSize(15,10);
    179         num11.setSize(15,10);
    180         
    181         num1.setText("01");
    182         num2.setText("02");
    183         num3.setText("03");
    184         num4.setText("04");
    185         num5.setText("05");
    186         num6.setText("06");
    187         num7.setText("07");
    188         num8.setText("08");
    189         num9.setText("09");
    190         num10.setText("10");
    191         num11.setText("11");
    192         
    193         
    194         num1.setLocation(10, 20);
    195         num2.setLocation(10, 40);
    196         num3.setLocation(10, 60);
    197         num4.setLocation(10, 80);
    198         num5.setLocation(10, 100);
    199         num6.setLocation(10, 120);
    200         num7.setLocation(10, 140);
    201         num8.setLocation(10, 160);
    202         num9.setLocation(10, 180);
    203         num10.setLocation(10, 200);
    204         num11.setLocation(10, 220);
    205         
    206         
    207         p4.add(num1);
    208         p4.add(num2);
    209         p4.add(num3);
    210         p4.add(num4);
    211         p4.add(num5);
    212         p4.add(num6);
    213         p4.add(num7);
    214         p4.add(num8);
    215         p4.add(num9);
    216         p4.add(num10);
    217         p4.add(num11);
    218         
    219         
    220     
    221     }
    222     
    223     //main方法   
    224     public static void main(String[] args) {
    225         //创建对象,运行主窗口   
    226         TomAwt_01 t=new TomAwt_01();
    227          t.init();
    228          t.setVisible(true);
    229          
    230            //监听事件,关闭窗口
    231            t.addWindowListener(new WindowAdapter() {
    232                public void windowClosing(WindowEvent e) {
    233                    System.exit(0); 
    234                }
    235            });
    236        }
    237 }
  • 相关阅读:
    ActiveReport9 在MVC4项目中出错
    EntityFramework5.0 DataBase-First 在三层架构中的使用,分离实体类到Model层。
    SqlServer存在并删除 表,函数,view等
    Visual Studio常用技巧与插件
    让 WPF 应用程序单例化
    C# 常用加密方法一 AES 与 DES
    Windows 的公共文件夹
    Hibernate中Criteria的完整用法
    maven依赖关系中Scope的作用
    Eclipse取消设置项目默认空间
  • 原文地址:https://www.cnblogs.com/borter/p/9434001.html
Copyright © 2020-2023  润新知