//HelloApplet.java
2 package hello;
3 import java.awt.FlowLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import javax.swing.*;
7 public class HelloApplet extends JApplet{
8 JLabel news=null;
9 public void init(){
10 setLayout(new FlowLayout());
11 news=new JLabel("你好,请单击按钮!");
12 add(news);
13 add(new JLabel(" "));
14 JButton tome=new JButton("汤姆");
15 add(tome);
16 JButton jake=new JButton("杰克");
17 add(jake);
18 tome.addActionListener(new ActionListener(){
19 public void actionPerformed(ActionEvent evt){
20 news.setText("汤姆,你好!");
21 }
22 }
23 );
24 jake.addActionListener(new ActionListener(){
25 public void actionPerformed(ActionEvent evt){
26 news.setText("杰克,你好!");
27 }
28 }
29 );
30 }
31
32 }
![]()
![]()
![]()