实验十 图形用户界面设计

1.源代码

package yaya;

import java.awt.*;

import javax.swing.*; 

public class Calculator extends Frame

{

String[] str= {"MC","C","PI","=","#","1","2","3","4","+","-","5","6","7","8","*","/","0","9",};

    

public Calculator()

{

    Panel pan=new Panel();

    this.setLayout(new GridLayout(4,4));

    this.setBackground(Color.blue);

    setLayout(new BorderLayout());

    for (int i = 0; i < str.length; i++) {

 

         pan.add(new Button(str[i]));

 

}

    TextField text = new TextField();

    this.add(text, BorderLayout.NORTH);

    this.add(pan, BorderLayout.CENTER);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setLocationRelativeTo(null);

    setResizable(false);

    

}

    

    private void setDefaultCloseOperation(int exitOnClose) {

    // TODO Auto-generated method stub

    

}

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        Calculator cal=new Calculator();

        cal.setTitle("计算器");

        cal.setSize(100,160);

        cal.setVisible (true );

2.实验心得

        在实现混合运算时比较困难,实现单独的加法器或者减法器之类的相对较容易实现,但是结合起来就很难设计,在编写代码的过程中遇到很多问题,后面通过查资料以及同学帮助,基本达到了实验目的。在以后得学习过程中还要努力,细心学习,尽量靠自己完成实验。

posted @ 2019-06-03 16:37  武智琳L  阅读(148)  评论(0编辑  收藏  举报