A Simple Swing Application with some components and layout

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.GridLayout;

public class MyFirstSwing extends JFrame {
    private JLabel lblMessage;
    private JLabel lblMsg;
    private JButton button;
    private JTextField txt;
    private JTextArea ta;
  
    MyFirstSwing() {
        lblMessage = new JLabel("Welcome to GUI!!!");
        lblMsg = new JLabel("Oh! I overlapped previous label");
        button = new JButton("Click Me");
        txt = new JTextField(5);
        ta = new JTextArea(2, 2);
      
        setLayout(new GridLayout(2, 1));
      
        add(lblMsg);
        add(lblMessage);
        //add(button);
        //add(txt);
        //add(ta);  
    }
  
    public static void main(String[] args) {
        MyFirstSwing frame = new MyFirstSwing();
        frame.setTitle("Title will be displayed here");
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

Comments

Popular posts from this blog

Zeller's Congruence

Property Event-Delegation

Method with variable arguments