zoukankan      html  css  js  c++  java
  • 实验十一 图形界面二

    1.源程序

    package jisuanqi2;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;


    public class Jisuanqi extends Frame implements ActionListener{
    public Jisuanqi() {
    super("计算器");
    Frame ff=new Frame("framework test");
    ff.setSize(400,100);
    ff.setLocation(300,240);
    ff.setLayout(new FlowLayout());
    final TextField f1=new TextField("10",8);
    ff.add(f1);

    //this.add(new Label("+"));
    Label l1=new Label("+");
    ff.add(l1);
    //this.add(new TextField("20",8));
    TextField f2=new TextField("20",8);
    ff.add(f2);
    //this.add(new Button("="));
    Button b1=new Button("=");
    ff.add(b1);
    //this.add(new TextField(10));
    TextField f3=new TextField(10);
    ff.add(f3);
    ff.addWindowListener(new myclose());
    ff.setVisible(true);
    b1.addActionListener(new ActionListener()
    {public void actionPerformed(ActionEvent e)
    {double c;
    String s1=f1.getText();
    double a=Integer.parseInt(s1);
    String s2=f2.getText();
    double b=Integer.parseInt(s2);
    c=a+b;
    String m=String.valueOf(c);
    f3.setText(m);

    }

    private double Integer(String s) {
    return 0;
    }
    });

    }

    class myclose implements WindowListener{

    public void windowActivated(WindowEvent arg0) {

    }

    public void windowClosed(WindowEvent arg0) {
    // TODO Auto-generated method stub

    }

    public void windowClosing(WindowEvent arg0) {

    System.exit(0);
    }

    public void windowDeactivated(WindowEvent arg0) {

    }

    public void windowDeiconified(WindowEvent arg0) {

    }

    public void windowIconified(WindowEvent arg0) {


    }

    public void windowOpened(WindowEvent arg0) {


    }

    }

    public static void main(String[] args) {

    new Jisuanqi();
    }


    public void actionPerformed(ActionEvent arg0) {

    }


    }

    2.实验结果

    3.实验心得:

               此次实验在上一次实验的基础上添加新的功能,用以实现为控件加监测实现驱动。在编写过程中遇到很多问题,不过在同学的帮助下解决了。对图形界面知识点的掌握还是不够熟练,以后还需要加强训练。

  • 相关阅读:
    优先队列插入、删除
    堆排序
    UVALive 2474 Balloons in a Box(枚举)
    二叉树的建立、四种遍历、求深度、求叶子结点数
    说说尾递归(转载)
    1#Two Sum(qsort用法)
    马克思:青年在选择职业时的考虑
    最要紧的是,我们首先要善良,其次是要诚实,再次是以后永远不要相互遗忘。
    多重背包优化算法
    poj2976 Dropping tests(01分数规划 好题)
  • 原文地址:https://www.cnblogs.com/wzl55/p/10994648.html
Copyright © 2011-2022 走看看