1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/* Create JLabel With Image Icon Example This java example shows how to create a label with image icon using Java Swing JLabel class. */ import javax.swing.ImageIcon; import javax.swing.JApplet; import javax.swing.JLabel; /* <applet code="JLabelWithIconExample" width=200 height=200> </applet> */ public class JLabelWithIconExample extends JApplet{ public void init(){ /* * Create an icon from an image using * ImageIcon(String imagePath, String description) * constructor. */ ImageIcon icon = new ImageIcon("images/copy.gif"); /* * To create a JLabel with image icon use, * JLabel(Icon icon) * constructor of JLabel class. */ JLabel copyLabel = new JLabel(icon); /* * Add label to an applet */ add(copyLabel); } } |
Add Comment