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个错误.真是搞不明白,我跟书上做的是一样,怎么会有错误.请高手指点一下?
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个错误.真是搞不明白,我跟书上做的是一样,怎么会有错误.请高手指点一下?
字符格式不对!
先粘贴到记事本中,保存,然后重名名为*.java
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考试!");
}
});
}
}
IDE来写程序
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考试!");
}
});
}
}
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考试!");
}
});
}
}
帮你改了一下
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考试!");
}
});
}
}