我想这样做,如果我点击JLabel,标签就会成为一个新标签,并附加了另一个图像.
到目前为止我的代码看起来像:
public class Picture extends JFrame {
private ImageIcon _image1;
private ImageIcon _image2;
private JLabel _mainLabel;
private JLabel _mainLabel2;
public Picture(){
_image1 = new ImageIcon("src/classes/picture1.jpg");
_image2 = new ImageIcon("src/classes/picture2.jpg");
_mainLabel = new JLabel(_image1);
_mainLabel2 = new JLabel(_image2);
add(_mainLabel);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Run Code Online (Sandbox Code Playgroud)