A Simple awt application with some components, layout and listener

import java.awt.Frame;
import java.awt.Label;
import java.awt.Button;
import java.awt.TextField;
import java.awt.TextArea;
import java.awt.FlowLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class MyFirstWindow extends Frame implements WindowListener {
    private Label lblMessage;
    private Label lblMsg;
    private Button button;
    private TextField txt;
    private TextArea ta;
   
    MyFirstWindow() {
        lblMessage = new Label("Welcome to GUI!!!");
        lblMsg = new Label("Oh! I overlapped previous label");
        button = new Button("Click Me");
        txt = new TextField(30);
        ta = new TextArea(10, 100);
       
        setLayout(new FlowLayout(FlowLayout.CENTER));
       
        add(lblMsg);
        add(lblMessage);
        add(button);
        add(txt);
        add(ta);
       
        addWindowListener(this);
    }
   
    public void windowOpened(WindowEvent e) { }
    public void windowClosing(WindowEvent e) {
        System.exit(1);
    }
    public void windowClosed(WindowEvent e) { }
    public void windowIconified(WindowEvent e) { }
    public void windowDeiconified(WindowEvent e) { }
    public void windowActivated(WindowEvent e) { }
    public void windowDeactivated(WindowEvent e) { }
       
    public static void main(String[] args) {
        MyFirstWindow frame = new MyFirstWindow();
        frame.setTitle("Title will be displayed here");
        frame.setSize(300, 300);
        frame.setVisible(true);
    }
}

Comments

Popular posts from this blog

Zeller's Congruence

Property Event-Delegation

Method with variable arguments