Friday, 5 October 2012

JLabel and imageIcon

This swing java program is used for displaying image, label in an applet.

place a required picture in a folder, copy and paste the following code in a note pad and
save as "" as the file name. Note that picture and java file must be stored
in the same folder.

compilation: javac
run: appletviewer

program code:

import java.awt.*;
import javax.swing.*;

/* <applet code="JLabelDemo" width=355 height=200>

public class JLabelDemo extends JApplet{

public void init() {
// Get content pane
Container contentPane = getContentPane();

// Create an icon
ImageIcon ii = new ImageIcon("sateesh.jpg");

// Create a label
JLabel jl = new JLabel ("SATEESH.BAGADHI", ii, JLabel.CENTER);

// Add label to the content pane

Post a Comment