就是下面的程序 提示
C:\Documents and Settings\Administrator\桌面\A(A类缺少标示符 窗口无法弹出).java:17: 需要 <标识符>
{
^
C:\Documents and Settings\Administrator\桌面\A(A类缺少标示符 窗口无法弹出).java:45: 需要 ';'
^
2 错误
处理已完成。
原程序 估计错误很多 请大虾帮忙修改
import java.awt.*;
import java.awt.event.*;
public static class A implements ActionListener
{
Frame f=new Frame("数据输入");
Button b1=new Button("确定");
TextField t1=new TextField();
TextField t2=new TextField();
Label L1=new Label("姓名:");
Label L2=new Label("密码:");
Checkbox c1=new Checkbox("男");
Checkbox c2=new Checkbox("女");
Choice ch1=new Choice("无");
TextArea ta1=new TextArea();
public A
{
f.add(L1);
f.add(t1);
f.add(L2);
f.add(t2);
f.add(c1);
f.add(c2);
f.add(ch1);
f.add(TextArea);
f.add(b1);
f.add(b2);
f.setSize(300,300);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){public viod windowclosing(WindowEvent e){System.exit(0);}}
}
public void actionPerformed(ActionEvent e)
{
ta.append(t1.getText());
ta.append(t2.getText());
ta.append(chc.getSelectedItem() );
ta.append(chc.getChoiceItem());
ta.append(chc.getTextAreaItem());
}
public static viod main(String[] args)
{ }
}
import java.awt.*; //JFrame要用到的类
import java.awt.event.*; //事件类
import javax.swing.*; //包含JFrame
public class MyWindow{
JFrame jframe=new JFrame(); //创建对象
JButton b1=new JButton("确定");
JTextField t1=new JTextField(10);
JPasswordField t2=new JPasswordField(10);
JLabel L1=new JLabel("姓名:");
JLabel L2=new JLabel("密码:");
Checkbox c1=new Checkbox("男");
Checkbox c2=new Checkbox("女");
JTextArea ta1=new JTextArea();
public MyWindow(String title){ //构造 初始化
jframe.setTitle(title); //设置标题
jframe.setSize(new Dimension(400,280)); //定义窗口大小
jframe.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
}
);
Panel p1=new Panel();
Panel p2= new Panel();
Panel p3= new Panel();
//mycontentp.setLayout(new BorderLayout()); 默认的布局
//添加组件
p1.setLayout(new BorderLayout());
p1.add(L1,BorderLayout.WEST);
p1.add(t1,BorderLayout.CENTER);
jframe.add(p1,BorderLayout.NORTH);
p2.add(L2,BorderLayout.WEST);
p2.add(t2,BorderLayout.CENTER);
jframe.add(p2,BorderLayout.CENTER);
p3.add(c1,BorderLayout.WEST);
p3.add(c2,BorderLayout.CENTER);
p3.add(b1,BorderLayout.EAST);
jframe.add(p3,BorderLayout.SOUTH);
jframe.setVisible(true);
}
public static void main(String args[]){
MyWindow mywin=new MyWindow("我的窗口");
}
}
重新给你做了一个,没添事件处理,布局没有调得太好,可以看一下.@_@
import java.awt.event.*;
public class A implements ActionListener
{
Frame f=new Frame("数据输入");
Button b1=new Button("确定");
TextField t1=new TextField();
TextField t2=new TextField();
Label L1=new Label("姓名:");
Label L2=new Label("密码:");
Checkbox c1=new Checkbox("男");
Checkbox c2=new Checkbox("女");
Choice ch1=new Choice();
TextArea ta1=new TextArea();
public void A ()
{
f.add(L1);
f.add(t1);
f.add(L2);
f.add(t2);
f.add(c1);
f.add(c2);
f.add(ch1);
f.add(ta1);
f.add(b1);
f.setSize(300,300);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){public void windowclosing(WindowEvent e){System.exit(0);}});
}
public void actionPerformed(ActionEvent e)
{
ta1.append(t1.getText());
ta1.append(t2.getText());
ta1.append(chc.getSelectedItem() ); //改到这里了,这三行我实在不知道是什么意思??
ta1.append(chc.getChoiceItem()); //哪来的变量chc?你想表达什么意思啊
ta1.append(chc.getTextAreaItem()); //你好多拼写错误啊,chc你想拼成什么?
}
public static void main(String[] args)
{ }
}
import java.awt.event.*;
public class ItisaFrame extends Frame{
Button b1 = new Button("确定");
TextField t1 = new TextField();
TextField t2 = new TextField();
Label L1 = new Label("姓名:");
Label L2 = new Label("密码:");
Checkbox c1 = new Checkbox("男");
Checkbox c2 = new Checkbox("女");
TextArea ta = new TextArea();
public static void main(String[] args) {
ItisaFrame f = new ItisaFrame();
f.showIt();
}
public void showIt() {
add(L1);
add(t1);
add(L2);
add(t2);
add(c1);
add(c2);
add(t1);
add(b1);
b1.addActionListener(new MyListener());
setSize(300, 300);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
class MyListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
ta.append(t1.getText());
ta.append(t2.getText());
ta.append(c1.getLabel());
ta.append(c1.getLabel());
}
}
}
您自学的?本回答被提问者采纳
}
上面的f.addWindowListener后面的应该是(,所以最后的应该是)而不是}
这里加上 );
f.addWindowListener(new WindowAdapter(){public viod windowclosing(WindowEvent e){System.exit(0);}} );