JFrame with JLabel

JLabel is the Swing component that creates a label, which is a component that displays information. The label is Swing’s simplest component because it is passive. That is, a label does not respond to user input. It just displays output. The program uses a JFrame container to hold an instance of a JLabel. The label displays a short text message.

Program

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JLabel;

class Frame extends JFrame{
    
    Frame()
    {
        setTitle("JLabel");
        JLabel jl = new JLabel("JLabel");
        add(jl);
        setSize(700, 200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

public class Javaapp {
   
    public static void main(String[] args) {
        
        Frame frame = new Frame();
    }
}

Leave a Comment