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()
{ JLabel prompt = new JLabel("请输入您的名字:");
final JTextField input = new JTextField(10);
final JTextField output = new JTextField(25);
JButton btnn = new JButton("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+",恭喜你成功了!");
}
});
}
}
======================================================
以上是在书上照抄的...可惜就是一直不成功..不知道为什么!