下面是我写的代码:运行后只显示窗体,窗体中什么都没有,抑郁很久... 刚学java ,还请问各位大神不吝赐教
packageMyCompute;importjava.awt.BorderLayout;//importjava.awt.Container;importjava.aw...
package MyCompute;
import java.awt.BorderLayout;
//import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MyCompute {
public void go(){
JFrame jf=new JFrame("我的计算器");
jf.setLayout(new BorderLayout());
jf.setSize(230,313);
jf.setResizable(false);//can't change window size
jf.setVisible(true);
JTextField jt=new JTextField();
jt.setEditable(false);//can't edit
jt.setText("请输入数字:");
JPanel jp1 =new JPanel();
jp1.setLayout(new GridLayout(4,5,2,1));
JPanel jp2=new JPanel();
jp2.setLayout(new GridLayout(1,3,2,1));
JPanel jp1and2=new JPanel();
jp1and2.setLayout(new BorderLayout(2,1));
JPanel jp3=new JPanel();
jp3.setLayout(new GridLayout(5,1,2,1));
JPanel jp1and2and3=new JPanel();
jp1and2and3.setLayout(new BorderLayout(2,1));
JButton jbMC=new JButton("MC");
JButton jbMR=new JButton("MR");
JButton jbMS=new JButton("MS");
JButton jbMplus=new JButton("M+");
JButton jbbackspace=new JButton("backspace");
JButton jbCE=new JButton("CE");
JButton jbC=new JButton("C");
JButton jbzhengf=new JButton("+/-");
JButton jb7=new JButton("7");
JButton jb8=new JButton("8");
JButton jb9=new JButton("9");
JButton jbchu=new JButton("/");
JButton jb4=new JButton("4");
JButton jb5=new JButton("5");
JButton jb6=new JButton("6");
JButton jbcheng=new JButton("*");
JButton jb1=new JButton("1");
JButton jb2=new JButton("2");
JButton jb3=new JButton("3");
JButton jbjian=new JButton("-");
JButton jb0=new JButton("0");
JButton jbPOINT=new JButton(".");
JButton jbplus=new JButton("+");
JButton jbMjian=new JButton("M-");
JButton jbsqr=new JButton("sqr");
JButton jbpercent=new JButton("%");
JButton jbdaoshu=new JButton("1/x");
JButton jbequals=new JButton("=");
//jp1 add
jp1.add(jbMC);
jp1.add(jbMR);
jp1.add(jbMS);
jp1.add(jbMplus);
jp1.add(jbbackspace);
jp1.add(jbCE);
jp1.add(jbC);
jp1.add(jbzhengf);
jp1.add(jb7);
jp1.add(jb8);
jp1.add(jb9);
jp1.add(jbchu);
jp1.add(jb4);
jp1.add(jb5);
jp1.add(jb6);
jp1.add(jbcheng);
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
jp1.add(jbjian);
//jp2 add
jp2.add(jb0);
jp2.add(jbPOINT);
jp2.add(jbplus);
//JP1and2 add
jp1and2.add(jp1,BorderLayout.NORTH);
jp1and2.add(jp2,BorderLayout.CENTER);
//jp3 add
jp3.add(jbMjian);
jp3.add(jbsqr);
jp3.add(jbpercent);
jp3.add(jbdaoshu);
jp3.add(jbequals);
//jp1and2and3
jp1and2and3.add(jp1and2,BorderLayout.CENTER);
jp1and2and3.add(jp3,BorderLayout.EAST);
//window add
jf.add(jt,BorderLayout.NORTH);
jf.add(jp1and2and3,BorderLayout.CENTER);
}
public static void main(String[] args){
MyCompute mycompute=new MyCompute();
mycompute.go();
}
} 展开
import java.awt.BorderLayout;
//import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MyCompute {
public void go(){
JFrame jf=new JFrame("我的计算器");
jf.setLayout(new BorderLayout());
jf.setSize(230,313);
jf.setResizable(false);//can't change window size
jf.setVisible(true);
JTextField jt=new JTextField();
jt.setEditable(false);//can't edit
jt.setText("请输入数字:");
JPanel jp1 =new JPanel();
jp1.setLayout(new GridLayout(4,5,2,1));
JPanel jp2=new JPanel();
jp2.setLayout(new GridLayout(1,3,2,1));
JPanel jp1and2=new JPanel();
jp1and2.setLayout(new BorderLayout(2,1));
JPanel jp3=new JPanel();
jp3.setLayout(new GridLayout(5,1,2,1));
JPanel jp1and2and3=new JPanel();
jp1and2and3.setLayout(new BorderLayout(2,1));
JButton jbMC=new JButton("MC");
JButton jbMR=new JButton("MR");
JButton jbMS=new JButton("MS");
JButton jbMplus=new JButton("M+");
JButton jbbackspace=new JButton("backspace");
JButton jbCE=new JButton("CE");
JButton jbC=new JButton("C");
JButton jbzhengf=new JButton("+/-");
JButton jb7=new JButton("7");
JButton jb8=new JButton("8");
JButton jb9=new JButton("9");
JButton jbchu=new JButton("/");
JButton jb4=new JButton("4");
JButton jb5=new JButton("5");
JButton jb6=new JButton("6");
JButton jbcheng=new JButton("*");
JButton jb1=new JButton("1");
JButton jb2=new JButton("2");
JButton jb3=new JButton("3");
JButton jbjian=new JButton("-");
JButton jb0=new JButton("0");
JButton jbPOINT=new JButton(".");
JButton jbplus=new JButton("+");
JButton jbMjian=new JButton("M-");
JButton jbsqr=new JButton("sqr");
JButton jbpercent=new JButton("%");
JButton jbdaoshu=new JButton("1/x");
JButton jbequals=new JButton("=");
//jp1 add
jp1.add(jbMC);
jp1.add(jbMR);
jp1.add(jbMS);
jp1.add(jbMplus);
jp1.add(jbbackspace);
jp1.add(jbCE);
jp1.add(jbC);
jp1.add(jbzhengf);
jp1.add(jb7);
jp1.add(jb8);
jp1.add(jb9);
jp1.add(jbchu);
jp1.add(jb4);
jp1.add(jb5);
jp1.add(jb6);
jp1.add(jbcheng);
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
jp1.add(jbjian);
//jp2 add
jp2.add(jb0);
jp2.add(jbPOINT);
jp2.add(jbplus);
//JP1and2 add
jp1and2.add(jp1,BorderLayout.NORTH);
jp1and2.add(jp2,BorderLayout.CENTER);
//jp3 add
jp3.add(jbMjian);
jp3.add(jbsqr);
jp3.add(jbpercent);
jp3.add(jbdaoshu);
jp3.add(jbequals);
//jp1and2and3
jp1and2and3.add(jp1and2,BorderLayout.CENTER);
jp1and2and3.add(jp3,BorderLayout.EAST);
//window add
jf.add(jt,BorderLayout.NORTH);
jf.add(jp1and2and3,BorderLayout.CENTER);
}
public static void main(String[] args){
MyCompute mycompute=new MyCompute();
mycompute.go();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询