Label Component in Java Swing


Simple code that explains how the JLabel component can be created in Java Swing.

File:la.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class la extends JFrame
{
JLabel l;
la()
{
setTitle(“Components Window”);
JPanel content=new JPanel();

l=new JLabel(“Label in Java Swing”);
l.setFont(new Font(“Arial”,Font.PLAIN,16));
content.add(l);
getContentPane().add(content);

myadapter my=new myadapter();
addWindowListener(my);
}
public class myadapter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public static void main(String ar[])
{
la a=new la();
a.setSize(400,400);
a.setVisible(true);
}
}

Output

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s