Show image by click JButton

后端 未结 3 1626
花落未央
花落未央 2020-12-12 02:39

I have a problem. I don\'t know how to display an image by clicking a JButton.

I have a class which can show and hide an image:

/**
 * 
 */
package          


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 03:20

    1) use JLabel#setIcon() instead of painting image as background to the JFrame

    2) create methods into class Selectie

    private void setIconToLabel (Icon icon){
    
         myDesiredLabel.setIcon(icon);
    }
    

    3) don't create a new JFrame for another image use CardLayout instaed

提交回复
热议问题