import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JLabelExam extends JApplet implements ActionListener{
JLabel lb1,lb2;
JButton bt;
JTextArea txtArea;
public void init(){
bt=new JButton( "确定 ");
txtArea=new JTextArea(10,20);
Icon icon1=new ImageIcon( "a1.gif ");
lb1=new JLabel( "标签1 ",icon1,JLabel.CENTER);
lb2=new JLabel( "标签2 ");
Container con=getContentPane();
con.add(txtArea,BorderLayout.CENTER);
con.add(bt,BorderLayout.WEST);
con.add(lb1,BorderLayout.NORTH);
con.add(lb2,BorderLayout.SOUTH);
bt.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
bt.setIcon(lb1.getIcon());
lb1.setHorizontalTextPosition(JLabel.LEFT);
}
}
------解决方案--------------------
楼主的程序用Applet运行,没有问题,一切正常!