How to add an
image to Jlabel or button in java Put an icon in java
Source code is below
package my_game;
/*dailymotion.com/abdul-wahab65*/
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Display{
public static void main(String[]args){
JFrame
frame = new JFrame();
JPanel
panel = new JPanel();
/*create an object
for Jlabel*/
JLabel
label = new JLabel();
frame.setSize(599,500);
frame.setVisible(true);
frame.add(panel);
panel.add(label);
label.setPreferredSize(new Dimension(599,500));
/*add
an image now
* copy the path of
* your file where your
* file is stored
*/
/*and make sure to
* type two back
* slashes
*/
ImageIcon
image = new ImageIcon
("C:\\Users\\abdul\\Desktop\\Dekstop\\New
folder\\aaa.jpg");
/*add
your image to
* the label
*/
label.setIcon(image);
}
No comments:
Post a Comment