其他分享
首页 > 其他分享> > 图形用户界面设计

图形用户界面设计

作者:互联网

图形用户界面设计

import java.awt.*;

import javax.swing.*;

 

public class JFramedemo extends JFrame {

private Box box;

private Container container;

private JTextField text;

private JPanel panel1,panel2;

private String S1[]={"Backspace","CE","C"};//将计算器上显示的内容存在数组里面

private String S2[]={"1","2","3","+","sqrt","4","5","6","-","%","7","8","9","*","1/x","0","+/-",".","/","="};

public JFramedemo(){

 this.setTitle("计算器显示界面");

 this.setBounds(300,300,500,500);

 container=getContentPane();

 container.setLayout(new FlowLayout());//将内容窗格设置成流式布局

 text=new JTextField(15);

 box=Box.createVerticalBox();

 panel1=new JPanel(new GridLayout(1,3,20,0));

 //panel1.setLayout(new GridLayout(1,3,10,0));

 panel2=new JPanel();

 panel2.setLayout(new GridLayout(4,5,10,10));

 for(int i=0;i<3;i++)//将数组S1的内容加到panel1的Button按钮上

 {

  panel1.add(new JButton(S1[i]));

 }

 for(int j=0;j<20;j++)//将数组S2的内容加到panel2的Button按钮上

 {

  panel2.add(new JButton(S2[j]));

 }

 box.add(text);

 box.add(Box.createVerticalStrut(15));

 box.add(panel1);

 box.add(Box.createVerticalStrut(25));

 box.add(panel2);

 container.add(box);

   pack();//调整窗口的大小,使其适应组件的大小和布局

 setVisible(true);

 this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

  public static void main(String[] args) {

 new JFramedemo();

   }

 

 

心得体会:在上节实验课时,我运行了此程序,显示是正确的,并有运行结果,不知道为啥,我在自己电脑上,显示很多错误,包括说在C盘下没有库,没有找到原因,下次会继续运行此程序!

标签:box,panel1,private,add,new,设计,panel2,图形用户界面
来源: https://www.cnblogs.com/wlyxjj/p/10968539.html