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 "JLabelDemo.java" as the file name. Note that picture and java file must be stored
in the same folder.
compilation: javac JLabelDemo.java
run: appletviewer JLabelDemo.java
program code:
-------------------------------------------------------------------------------------------
import java.awt.*;
import javax.swing.*;
/* <applet code="JLabelDemo" width=355 height=200>
</applet>
*/
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
contentPane.add(jl);
}
}
-----------------------------------------------------------------------------------------
output: