求指教,关于计算器界面的问题
小弟有一代码不能找出错误的原因,请大神指教:package javatest03;
import java.
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class JavaTest_3_GUI_V1 extends JFrame implements ActionListener
{
/**/
private static final long serialVersionUID = 1L;
// 第一步:确定间隔、大小等界面上的常量,以像素点为单位
private static final int ComponentHeight = 30;
private static final int ButtonWidth = 50;
private static final int ComponentSpaceX = 10;
private static final int ComponentSpaceY = 10;
private static final int OriginOffsetY = 5;
private static final int OriginOffsetX = 5;
private static final int outPutFieldWidth = 700;
// 第二步,依次创建各个按钮
JTextField outputField = new JTextField(150);
JButton buttonOne = new JButton("1");
JButton buttonTwo = new JButton("2");
JButton buttonThree = new JButton("3");
JButton buttonFour = new JButton("4");
JButton buttonFive = new JButton("5");
JButton buttonSix = new JButton("6");
JButton buttonSeven = new JButton("7");
JButton buttonEight = new JButton("8");
JButton buttonNine = new JButton("9");
JButton buttonZero = new JButton("0");
JButton buttonLess = new JButton("<__");
JButton buttonPlus = new JButton("+");
JButton buttonReduce = new JButton("-");
JButton buttonAsterisk= new JButton("*");
JButton buttonBias = new JButton("/");
JButton buttonPoint = new JButton(".");
JButton buttonEqual = new JButton("=");
JButton buttonClear = new JButton("CE");
// 第三不,生成各控件的相对于主窗口的矩形位置(原点x值,原点y值,宽,高)
Rectangle boundOutputField =
new Rectangle(OriginOffsetY + 0 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 0 *(ComponentSpaceY + ComponentHeight),
outPutFieldWidth, ComponentHeight);
Rectangle boundButtonOne =
new Rectangle(OriginOffsetY + 0 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonTwo =
new Rectangle(OriginOffsetY + 1 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonThree =
new Rectangle(OriginOffsetY + 2 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonfour =
new Rectangle(OriginOffsetY + 3 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonFive =
new Rectangle(OriginOffsetY + 4 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonSix =
new Rectangle(OriginOffsetY + 5 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonSeven =
new Rectangle(OriginOffsetY + 6 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonEight =
new Rectangle(OriginOffsetY + 7 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonNine =
new Rectangle(OriginOffsetY + 8 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonZero =
new Rectangle(OriginOffsetY + 9 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 1 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonLess =
new Rectangle(OriginOffsetY + 0 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 2 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonPlus =
new Rectangle(OriginOffsetY + 1 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 2 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonAsterisk =
new Rectangle(OriginOffsetY + 2 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 2 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonBias =
new Rectangle(OriginOffsetY + 3 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 2 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonPoint =
new Rectangle(OriginOffsetY + 4 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 2 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonEqual =
new Rectangle(OriginOffsetY + 5 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 2 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
Rectangle boundButtonClear =
new Rectangle(OriginOffsetY + 6 *(ComponentSpaceX + ButtonWidth), OriginOffsetX + 2 *(ComponentSpaceY + ComponentHeight),
ButtonWidth, ComponentHeight);
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
JavaTest_3_GUI_V1 frame = new JavaTest_3_GUI_V1();
frame.setTitle("JavaTest_3_GUI_V1");
frame.setLocation(100, 100);
frame.setSize(outPutFieldWidth + 3 * OriginOffsetY, 350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public JavaTest_3_GUI_V1()
{
setLayout(null);
// 第四步:设置控件额外的属性
// output text field configuration and initialization
// 设置outputField的边界(相对于主窗口的位置和大小)
outputField.setBounds(boundOutputField);
// 设置oututField的字符串显示顺序,设为从右到左显示
outputField.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
// 设置outputField内的默认内容,应该显示为“0.”
outputField.setText(".0");
// 禁止从界面(键盘)直接向outputField输入信息,只能通过程序改变outputField的内容
outputField.setEditable(false);
// Number buttons configuration and initialization
// 第五步:通过设置各控件的边界设置控件的坐标和大小
buttonOne.setBounds(boundButtonOne);
buttonTwo.setBounds(boundButtonTwo);
// buttonOne.setBackground(Color.RED);
// Operations configuration and initialization
buttonPlus.setBounds(boundButtonPlus);
buttonEqual.setBounds(boundButtonEqual);
buttonClear.setBounds(boundButtonClear);
// Add TextFields and buttons to the content panel
// 第六步:把各个界面元素按照指定的位置加入主界面
add(outputField);
add(buttonOne);
add(buttonTwo);
add(buttonThree);
add(buttonFour);
add(buttonFive);
add(buttonSix);
add(buttonSeven);
add(buttonEight);
add(buttonNine);
add(buttonZero);
add(buttonLess);
add(buttonPlus);
add(buttonReduce);
add(buttonAsterisk);
add(buttonBias);
add(buttonPoint);
add(buttonEqual);
add(buttonClear);
// Register action listener so as to handle events from the JFrame window
// 第七步:为各个按钮注册(鼠标左击)事件处理器(JavaTest_5_GUI_V1.actionPerformed)
buttonOne.addActionListener(this);
buttonTwo.addActionListener(this);
buttonThree.addActionListener(this);
buttonFour.addActionListener(this);
buttonFive.addActionListener(this);
buttonSix.addActionListener(this);
buttonSeven.addActionListener(this);
buttonEight.addActionListener(this);
buttonNine.addActionListener(this);
buttonZero.addActionListener(this);
buttonLess.addActionListener(this);
buttonplus.addActionListener(this);
buttonReduce.addActionListener(this);
buttonAsterisk.addActionListener(this);
buttonBias.addActionListener(this);
buttonPoint.addActionListener(this);
buttonEqual.addActionListener(this);
buttonClear.addActionListener(this);
}
}
因为我是初学者,那些很繁琐的过程不会用数组输入,所以程序就这样长。劳烦帮我找一下错误,并提示一下怎样改,
谢谢!!!