zoukankan      html  css  js  c++  java
  • 39

    package test_17;

    import java.awt.*;
    import java.awt.event.*;

    public class Calc1 implements ActionListener
    {
    Frame f;
    TextField tf1;
    Button b1,b2,b3,b4;
    public void display()
    {
    f = new Frame("Calculation");
    f.setSize(260,150);
    f.setLocation(320,240); //设置窗口初始位置
    f.setBackground(Color.lightGray);
    f.setLayout(new FlowLayout(FlowLayout.LEFT));//改变布局且左对齐
    tf1 = new TextField(30);
    tf1.setEditable(false); //只能显示,不允许编辑
    f.add(tf1);
    b1 = new Button("1");
    b2 = new Button("2");
    b3 = new Button("+");
    b4 = new Button("TZ(清屏)");
    f.add(b1);
    f.add(b2);
    f.add(b3);
    f.add(b4);
    b1.addActionListener(this); //为按钮b1注册事件监听程序
    b2.addActionListener(this);
    b3.addActionListener(this);
    b4.addActionListener(this);
    f.addWindowListener(new WinClose()); //为框架f注册事件监听程序
    f.setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    { //实现ActionListener接口中的方法,单击按钮时产生该事件
    if (e.getSource()==b4) //获得产生事件的对象
    tf1.setText("");//清屏
    else //获取按钮标签,重新设置文本内容
    tf1.setText(tf1.getText()+e.getActionCommand());
    }
    public static void main(String arg[])
    {
    (new Calc1()).display();
    }
    }

    class WinClose extends WindowAdapter
    {
    public void windowClosing(WindowEvent e)
    { //覆盖WindowAdapter类中同名方法,单击窗口关闭按钮时产生该事件
    System.exit(0); //结束程序运行,关闭窗口
    }
    }

  • 相关阅读:
    表单之input的样式修改
    文本省略和文本垂直居中展示
    text-align:justify的使用
    10- 禅道使用
    09- 软件缺陷
    08- 测试用例详解
    07- 场景分析法
    01- Python语言简介
    08. linux下 mv find grep命令
    1.4.19- HTML标签之注释标签
  • 原文地址:https://www.cnblogs.com/acm-icpcer/p/6666737.html
Copyright © 2011-2022 走看看