A
ahui
Unregistered / Unconfirmed
GUEST, unregistred user!
使用java 2 SDK编译不对功,程序是书上的!错误提示如下:
c9_5.java:3: 'class' or 'interface' expected
improt java.awt.event.*;
^
1 error
源码如下:
import javax.swing.*;
import java.awt.*;
improt java.awt.event.*;
public class c9_5 extends JApplet implements ActionListener
{
Container ctp=getContentPane();
JLabel lb1=new JLabel("输入文字后按回车:",JLabel.CENTER),
lb2=new JLabel("输出结果:",JLabel.CENTER);
JTextField tf1=new JTextField(10);
JTestArea tf2=new JTextArea(5,10);
public void init()
{
ctp.setLayout(new FlowLayout());
ctp.add(lb1);
ctp.add(lb2);
tf1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String str;
str=tf1.getText();
tf2.append(str+"/n");
}
}
c9_5.java:3: 'class' or 'interface' expected
improt java.awt.event.*;
^
1 error
源码如下:
import javax.swing.*;
import java.awt.*;
improt java.awt.event.*;
public class c9_5 extends JApplet implements ActionListener
{
Container ctp=getContentPane();
JLabel lb1=new JLabel("输入文字后按回车:",JLabel.CENTER),
lb2=new JLabel("输出结果:",JLabel.CENTER);
JTextField tf1=new JTextField(10);
JTestArea tf2=new JTextArea(5,10);
public void init()
{
ctp.setLayout(new FlowLayout());
ctp.add(lb1);
ctp.add(lb2);
tf1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String str;
str=tf1.getText();
tf2.append(str+"/n");
}
}