package a1;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class JLabel01 extends JFrame implements ActionListener{
JLabel a1;//图像标签
JLabel a2;//文本标签
JPanel b1;//面板
JButton c1;//按钮
public JLabel01(String name){
super(name);
this.c1=new JButton("标签测试");//设置按钮
this.a1=new JLabel("显示图像");//设置图像标签
this.a2=new JLabel("显示文本");//设置文本标签
this.b1=new JPanel();
b1.add(a1);//把图像标签加入面板
b1.add(a2);//把文本标签加入面板
b1.add(c1);//把按钮加入面板
this.add(b1);
this.setBounds(500,200,300,300);
c1.addActionListener(this);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
ImageIcon d1=new ImageIcon(getClass().getResource("C:/Users/admin/Pictures/Nitro/Nitro_Wallpaper_5000x2813.jpg"));
this.a1.setText(null);
this.a1.setIcon(d1);
this.a2.setText("文本修改");
}
public static void main(String args){
new JLabel01("标签演示框架");
}
}