import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WelcomeTest 
{public static void main(String []args)
   {WelcomeFrame frame = new WelcomeFrame();
      frame.setDefaultCloseOperation(Frame.EXIT_ON_CLOSE);
     frame.show();
   }
}
class WelcomeFrame extends Frame
{  public WelcomeFrame()
   {   setTitle("Welcome");
     setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
   WelcomePanel panel = new WelcomePanel();
   Container contentPane = getContentPane();
   contentPane.add(panel);
   }
   public static final intDEFAULT_WIDTH = 300;
   Public static final intDEFAULT_HEIGHT = 200;
}
class WelcomePanel extends Panel
{  public WelcomePanel()
   {  Label prompt = new Label("请输入您的名字:")
       final TextField input = new TextField(10);
     final TextField output = new TextField(25);
       Button  btnn = new Button("Welcome");
      add(prompt);
     add(input);
      add(output);
      add(btnn);
  btnn.addActionListener(new
      ActionListener()
       {  public void actionPerformed(ActionEvent event)
         {  String s = input.getText();
          output.setText("Hello"+s+",欢迎您参加Java考试!");
         }
      });
    }
}
   \\就是这个源程序,用JAVAC编译的时候,报告有100个错误.真是搞不明白,我跟书上做的是一样,怎么会有错误.请高手指点一下?

解决方案 »

  1.   

    是直接拷贝的吧:)
    字符格式不对!
    先粘贴到记事本中,保存,然后重名名为*.java
      

  2.   

    改了以下,可以了
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class WelcomeTest {
        public static void main(String []args)   {
            WelcomeFrame frame = new WelcomeFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.show();
        }
    }
    class WelcomeFrame extends JFrame{  
        public WelcomeFrame()   { 
            setTitle("Welcome");
            setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
            WelcomePanel panel = new WelcomePanel();
            Container contentPane = getContentPane();
            contentPane.add(panel);
       }
       public static final int DEFAULT_WIDTH = 300;
       public static final int DEFAULT_HEIGHT = 200;
    }
    class WelcomePanel extends Panel{  
        public WelcomePanel()   {  
            Label prompt = new Label("请输入您的名字:");
            final TextField input = new TextField(10);
            final TextField output = new TextField(25);
            Button  btnn = new Button("Welcome");
            add(prompt);
            add(input);
            add(output);
            add(btnn);
            btnn.addActionListener(new ActionListener(){ 
                public void actionPerformed(ActionEvent event){  
                    String s = input.getText();
                    output.setText("Hello"+s+",欢迎您参加Java考试!");
                }
            });
        }
    }
      

  3.   

    要保证你编译正确才能运行,classpath那些要设置正确,最好有个
    IDE来写程序
      

  4.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class WelcomeTest {
        public static void main(String[] args) {
            WelcomeFrame frame = new WelcomeFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.show();
        }
    }class WelcomeFrame extends JFrame {
        public WelcomeFrame() {
            setTitle("Welcome");
            setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
            WelcomePanel panel = new WelcomePanel();
            Container contentPane = this.getContentPane();
            contentPane.add(panel);
        }    public static final int DEFAULT_WIDTH = 300;
        public static final int DEFAULT_HEIGHT = 200;
    }class WelcomePanel extends Panel {
        public WelcomePanel() {
            Label prompt = new Label("请输入您的名字:");
            final TextField input = new TextField(10);
            final TextField output = new TextField(25);
            Button btnn = new Button("Welcome");
            add(prompt);
            add(input);
            add(output);
            add(btnn);
            btnn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    String s = input.getText();
                    output.setText("Hello" + s + ",欢迎您参加Java考试!");
                }
            });
        }
    }
      

  5.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class WelcomeTest {
    public static void main(String[] args) {
    WelcomeFrame frame = new WelcomeFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.show();
    }
    }class WelcomeFrame extends JFrame {
    public WelcomeFrame() {
    setTitle("Welcome");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
    WelcomePanel panel = new WelcomePanel();
    Container contentPane = getContentPane();
    contentPane.add(panel);
    } public static final int DEFAULT_WIDTH = 300; public static final int DEFAULT_HEIGHT = 200;
    }class WelcomePanel extends JPanel {
    public WelcomePanel() {
    Label prompt = new Label("请输入您的名字:");
    final TextField input = new TextField(10);
    final TextField output = new TextField(25);
    Button btnn = new Button("Welcome");
    add(prompt);
    add(input);
    add(output);
    add(btnn);
    btnn.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {
    String s = input.getText();
    output.setText("Hello" + s + ",欢迎您参加Java考试!");
    }
    });
    }
    }
      

  6.   

    你要是用Eclipse就会发现很好改错的~
      

  7.   

    你一定没有注意到Frame和JFrame的区别
    帮你改了一下
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class WelcomeTest 
    {public static void main(String []args)
       {WelcomeFrame frame = new WelcomeFrame();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//setDefaultCloseOperation();
         frame.show();
       }
    }
    class WelcomeFrame extends JFrame
    {  public WelcomeFrame()
       {   setTitle("Welcome");
         setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
       WelcomePanel panel = new WelcomePanel();
       Container contentPane =getContentPane();
       contentPane.add(panel);
       }
        public static final  int DEFAULT_WIDTH = 300;
       public static final int DEFAULT_HEIGHT = 200;
    }
    class WelcomePanel extends Panel
    {  public WelcomePanel()
       {  Label prompt = new Label("请输入您的名字:");
           final TextField input = new TextField(10);
         final TextField output = new TextField(25);
           Button  btnn = new Button("Welcome");
          add(prompt);
         add(input);
          add(output);
          add(btnn);
      btnn.addActionListener(new
          ActionListener()
           {  public void actionPerformed(ActionEvent event)
             {  String s = input.getText();
              output.setText("Hello"+s+",欢迎您参加Java考试!");
             }
          });
        }
    }