代码:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DoubleIt extends JApplet implements actionListener {
JLable lValue;
JTextField tValue;
JButton bDoubble;
public void init(){
setSize(200,400);
Container panel;
panel = getContent.Pane();
panel.setLayout( new FlowLayout());
lValue = new JLable("Int Value");
tValue = new Jtextfield(15);
tValue.SetText("125");
panel.add(lValue);
panel.add(tValue);
bDoubble = new JButton("*");
panel.add(bDoubble);
bDoubble.add.ActionListiner(this);
}//end init
public void actionPerformed(ActionEvent event);
int value;
value = Integer.parseInt(tValue.getText());
value = value * 2;
tValue.setText(" "+value);
}//end method
}//end main
错误:
DoubleIt.java:27:错误:预期的标识符
value = Integer.parseInt(tValue.getText());
^
DoubleIt.java:28:错误:预期的标识符
value = value * 2;
^
DoubleIt.java:29:错误:预期的标识符
tValue.setText(" "+value);
^
DoubleIt.java:29:错误:非法启动类型
tValue.setText(" "+value);
^
DoubleIt.java:29:错误:')'预期
tValue.setText(" "+value);
^
DoubleIt.java:29:错误:';'预期
tValue.setText(" "+value);
^
DoubleIt.java:29:错误:非法启动类型
tValue.setText(" "+value);
^
DoubleIt.java:29:错误:预期的标识符
tValue.setText(" "+value);
^
DoubleIt.java:29:错误:';'预期
tValue.setText(" "+value);
^
我的问题:
我有编译器说我缺少的所有东西,这是一个括号问题吗?
答案 0 :(得分:3)
你的问题在这里......
public void actionPerformed(ActionEvent event); <--- See the semi colen...
应该是......
public void actionPerformed(ActionEvent event) {
和...
JLable lValue;
//...
lValue = new JLable("Int Value");
应该是......
JLabel lValue;
//...
lValue = new JLabel("Int Value");
和...
tValue = new Jtextfield(15);
应该是......
tValue = new JTextField(15);
和...
tValue.SetText("125");
应该是......
tValue.setText("125");
和...
bDoubble.add.ActionListiner(this);
应该是......
bDoubble.addActionListener(this);
和...
public class DoubleIt extends JApplet implements actionListener
应该是......
public class DoubleIt extends JApplet implements ActionListener
和...
panel = getContent.Pane();
应该是......
panel = getContentPane();
请记住,Java区分大小写,案例很重要
答案 1 :(得分:0)
更改
public void actionPerformed(ActionEvent event);
要
public void actionPerformed(ActionEvent event) {
答案 2 :(得分:0)
你在方法声明后加了一个分号:
public void actionPerformed(ActionEvent event);
将;
替换为{
(左大括号)