container=getContentPane(); 为什么老说'需要<标识符>'
import java.awt.*;
import java.text.DecimalFormat ;
import java.awt.event.*;
import javax.swing.*;public class MyC extends JFrame
{
public JPanel p1,p2,p3,p4,p5,p0;
private JTextField jText ;
DecimalFormat df ;//设置数据输出精度
private String lastCommand ;//保存+,-,*,/,=命令
private double result ;//保存计算结果
private boolean start ;//判断是否为数字的开始
public Container container;
private BorderLayout layout ;
public MyC()
{
super("计算器");
p1=new JPanel();
p1.setLayout( new FlowLayout( ));
p1.add( new JButton("MC") );
p1.add( new JButton("MR") );
p1.add( new JButton("MS") );
p1.add( new JButton("M+") );
setSize(40,160); setVisible(true); setResizable(false);
JPanel p2=new JPanel();
p2.setLayout( new FlowLayout( ));
p2.add( new JButton("/") );
p2.add( new JButton("sqrt") );
p2.add( new JButton("*") );
p1.add( new JButton("%") );
p1.add( new JButton("-") );
p2.add( new JButton("1/x") );
p2.add( new JButton("+") );
p2.add( new JButton("=") );
setSize(80,160); setVisible(true); setResizable(false); JPanel p3=new JPanel();
p3.setLayout( new FlowLayout( ));
p3.add( new JButton("Backspace") );
p3.add( new JButton("CE") );
p3.add( new JButton("C") );
setSize(120,40); setVisible(true); setResizable(false);
JPanel p4=new JPanel();
p4.setLayout( new FlowLayout( ));
p4.add( new JButton("0") );
p4.add( new JButton("+/-") );
p4.add( new JButton(".") );
setSize(120,40); setVisible(true); setResizable(false);
int i;
String label;
JPanel p5=new JPanel();
p5.setLayout( new FlowLayout( ));
for(i=0;i<10;i++)
{
p5.add( new JButton("i") );
}
setSize(120,120); setVisible(true); setResizable(false);
}
JTextField jText=new JTextField(20);
container=getContentPane();
layout=new BorderLayout();
container.setLayout(layout);
container.add( jText,BorderLayout.NORTH);
container.add( p3,BorderLayout.NORTH);
container.add( p5 ,BorderLayout.CENTER);
container.add( p1 ,BorderLayout.WEST);
container.add( p2 ,BorderLayout.EAST);
container.add( p4 ,BorderLayout.SOUTH);
setSize(280,260); setVisible(true); setResizable(false);
start=true ;
result=0 ;
df=new DecimalFormat("0.##############");//设置数据输出精度(对于double型值)
lastCommand="=" ;
jText=new JTextField("0");
jText.setHorizontalAlignment(JTextField.RIGHT);
}
import java.awt.*;
import java.text.DecimalFormat ;
import java.awt.event.*;
import javax.swing.*;public class MyC extends JFrame
{
public JPanel p1,p2,p3,p4,p5,p0;
private JTextField jText ;
DecimalFormat df ;//设置数据输出精度
private String lastCommand ;//保存+,-,*,/,=命令
private double result ;//保存计算结果
private boolean start ;//判断是否为数字的开始
public Container container;
private BorderLayout layout ;
public MyC()
{
super("计算器");
p1=new JPanel();
p1.setLayout( new FlowLayout( ));
p1.add( new JButton("MC") );
p1.add( new JButton("MR") );
p1.add( new JButton("MS") );
p1.add( new JButton("M+") );
setSize(40,160); setVisible(true); setResizable(false);
JPanel p2=new JPanel();
p2.setLayout( new FlowLayout( ));
p2.add( new JButton("/") );
p2.add( new JButton("sqrt") );
p2.add( new JButton("*") );
p1.add( new JButton("%") );
p1.add( new JButton("-") );
p2.add( new JButton("1/x") );
p2.add( new JButton("+") );
p2.add( new JButton("=") );
setSize(80,160); setVisible(true); setResizable(false); JPanel p3=new JPanel();
p3.setLayout( new FlowLayout( ));
p3.add( new JButton("Backspace") );
p3.add( new JButton("CE") );
p3.add( new JButton("C") );
setSize(120,40); setVisible(true); setResizable(false);
JPanel p4=new JPanel();
p4.setLayout( new FlowLayout( ));
p4.add( new JButton("0") );
p4.add( new JButton("+/-") );
p4.add( new JButton(".") );
setSize(120,40); setVisible(true); setResizable(false);
int i;
String label;
JPanel p5=new JPanel();
p5.setLayout( new FlowLayout( ));
for(i=0;i<10;i++)
{
p5.add( new JButton("i") );
}
setSize(120,120); setVisible(true); setResizable(false);
}
JTextField jText=new JTextField(20);
container=getContentPane();
layout=new BorderLayout();
container.setLayout(layout);
container.add( jText,BorderLayout.NORTH);
container.add( p3,BorderLayout.NORTH);
container.add( p5 ,BorderLayout.CENTER);
container.add( p1 ,BorderLayout.WEST);
container.add( p2 ,BorderLayout.EAST);
container.add( p4 ,BorderLayout.SOUTH);
setSize(280,260); setVisible(true); setResizable(false);
start=true ;
result=0 ;
df=new DecimalFormat("0.##############");//设置数据输出精度(对于double型值)
lastCommand="=" ;
jText=new JTextField("0");
jText.setHorizontalAlignment(JTextField.RIGHT);
}
p5.setLayout( new FlowLayout( ));
for(i=0;i<10;i++)
{
p5.add( new JButton("i") );
}
setSize(120,120); setVisible(true); setResizable(false);
}多了一个 " } "