- 论坛徽章:
- 0
|
我写了个计算器的小程序,下面这个程序只是实现图形界面功能的,当我编译的时候报错,
错误如下:
'class' or 'interface' expected!
错误的行数我在下面完整的程序中用黑体表示出来了。
想不通这是什么问题,希望能有哪个高手指点一下,谢谢。
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class calculator2 extends Jpanel{
- static JFrame frame;
- static JPanel subPanel;
- static String add = "+";
- static String substract = "-";
- static String multiply = "*";
- static String divide = "/";
- JTextField num1TextField, num2TextField, resultTextField;
- JButton equalButton;
- ButtonGroup group;
- JRadioButton addButton, substractButton, multiplyButton, divideButton;
- public calculator2()
- {
- num1TextField = new JTextField(5);
- num2TextField = new JTextField(5);
- resultTextField = new JTextField(5);
- equalButton = new JButton("=");
- addButton = new JRadioButton(add);
- addButton.setActionCommand(add);
- substractButton = new JRadioButton(substract);
- substractButton.setActionCommand(substract);
- multiplyButton = new JRadioButton(multiply);
- multiplyButton.setActionCommand(multiply);
- divideButton = new JRadioButton(divide);
- divideButton.setActionCommand(divide);
- group = new ButtonGroup();
- group.add(addButton);
- group.add(substractButton);
- group.add(multiplyButton);
- group.add(divideButton);
- addButton.setSelected(true);
- subPanel = new Jpanel();
- subPanel.setLayout(new GridLayout(4, 1));
- subPanel.add(addButton);
- subPanel.add(substractButton);
- subPanel.add(multiplyButton);
- subPanel.add(divideButton);
- add(num1TextField);
- add(subPanel);
- add(num2TextField);
- add(equalButton);
- add(resultTextField);
- }
- }
- [b]public static void main(String args[]){[/b] //class or interface expected!
- try{
- UIManager.setLookAndFeel(UIMananger.getSystemLookAndFeelClassName());
- }catch(Exception exc){
- System.err.println("Error loading L&F: " + exc);
- }
- calculator2 panel = new calculator2();
- frame = new JFrame("calculator");
- frame.addWindowListener(new WindowAdapter(){
- public void windowClosing(windowEvent e){System.exit(0);}
- };
- frame.getContentPane().add("Center", panel);
- frame.pack();
- frame.setVisible(true);
- }
复制代码 |
|