Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JFrame;

public class Main {
    public static void main() {

        ComponentListener listener = new ComponentAdapter() {
            public void componentShown(ComponentEvent evt) {
                Component c = (Component) evt.getSource();
                System.out.println("Component is now visible");
            }

            public void componentHidden(ComponentEvent evt) {
                Component c = (Component) evt.getSource();
                System.out.println("Component is now hidden");
            }

            public void componentMoved(ComponentEvent evt) {
                Component c = (Component) evt.getSource();

                Point newLoc = c.getLocation();
                System.out.println("Get new location");
            }

            public void componentResized(ComponentEvent evt) {
                Component c = (Component) evt.getSource();

                Dimension newSize = c.getSize();
                System.out.println("Get new size");
            }
        };
        JFrame frame = new JFrame();
        frame.setSize(300, 300);
        frame.addComponentListener(listener);
        frame.setVisible(true);
    }
}