其他分享
首页 > 其他分享> > 实验十:图形用户界面设计

实验十:图形用户界面设计

作者:互联网

实验代码:

package 实验10;
import java.awt.Container;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.WindowConstants;

public class Jisuanqi extends JFrame{
public void Create(String title) {
JFrame jf =new JFrame(title);
Container c=jf.getContentPane();
jf.setVisible(true);
jf.setLayout(null);
jf.setSize(400,400);
jf.setBounds(0,0,230,300);
JButton b1=new JButton("1");
JButton b2=new JButton("2");
JButton b3=new JButton("3");
JButton b4=new JButton("4");
JButton b5=new JButton("5");
JButton b6=new JButton("6");
JButton b7=new JButton("7");
JButton b8=new JButton("8");
JButton b9=new JButton("9");
JButton b10=new JButton("0");
JButton b11=new JButton("+");
JButton b12=new JButton("-");
JButton b13=new JButton("*");
JButton b14=new JButton("/");
JButton b15=new JButton("en");
b1.setBounds(10,10,50,50);
b2.setBounds(60,10,50,50);
b3.setBounds(110,10,50,50);
b4.setBounds(10,60,50,50);
b5.setBounds(60,60,50,50);
b6.setBounds(110,60,50,50);
b7.setBounds(10,110,50,50);
b8.setBounds(60,110,50,50);
b9.setBounds(110,110,50,50);
b10.setBounds(10,160,50,50);
b11.setBounds(60,160,50,50);
b12.setBounds(110,160,50,50);
b13.setBounds(160,10,50,50);
b14.setBounds(160,60,50,50);
b15.setBounds(160,110,50,100);
c.add(b1);
c.add(b2);
c.add(b3);
c.add(b4);
c.add(b5);
c.add(b6);
c.add(b7);
c.add(b8);
c.add(b9);
c.add(b10);
c.add(b11);
c.add(b12);
c.add(b13);
c.add(b14);
c.add(b15);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Jisuanqi().Create("计算器");
}

}

实验结果:

 

标签:10,setBounds,50,add,实验,new,设计,JButton,图形用户界面
来源: https://www.cnblogs.com/itsRes/p/10963293.html