Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Form load event handler in Java?

Tags:

java

What is the event handler in Java (using net beans) that resembles the From_Load in C#?

like image 651
Ahmad Farid Avatar asked Mar 12 '10 12:03

Ahmad Farid


People also ask

What is form load event?

The Form Load Event in VB . NET. An important event you'll want to write code for is the Form Load event. You might want to, for example, set the Enabled property of a control to False when a form loads. Or maybe blank out an item on your menu.

What is load event in javascript?

The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images. This is in contrast to DOMContentLoaded , which is fired as soon as the page DOM has been loaded, without waiting for resources to finish loading.

Which function is called for loading of a window form?

Load Event (System. Windows. Forms) | Microsoft Learn.

How do you call a load event in C#?

You have to call Form_load. Form_Load(this, null);


2 Answers

This simple sample is useful.

public static void main(String[] args) {

    JFrame fa = new JFrame();
    fa.setBounds(100, 100, 400, 200);
    fa.setVisible(true);
    fa.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
            JOptionPane.showMessageDialog(fa, "windowOpened");
        }

        @Override
        public void windowClosing(WindowEvent e) {
            JOptionPane.showMessageDialog(fa, "windowClosing");
        }

        @Override
        public void windowClosed(WindowEvent e) {
            JOptionPane.showMessageDialog(fa, "windowClosed");
        }

        @Override
        public void windowIconified(WindowEvent e) {
            JOptionPane.showMessageDialog(fa, "windowIconified");
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
            JOptionPane.showMessageDialog(fa, "windowDeiconified");
        }

        @Override
        public void windowActivated(WindowEvent e) {
        //                JOptionPane.showMessageDialog(fa, "windowActivated");
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        //                JOptionPane.showMessageDialog(fa, "windowDeactivated");
        }
    });
}
like image 81
Sajad NasiriNezhad Avatar answered Oct 16 '22 19:10

Sajad NasiriNezhad


Whilst the accepted answer is based on the underlying WindowListener interface (which forces you to provide an implementation for each type of event you can use) the WindowAdapter where you can override the appropriate event you are interested in.

public class MySwingJFrame extends JFrame {
    public MySwingJFrame() {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                // do something
            }
        });
    }
}
like image 30
Andez Avatar answered Oct 16 '22 18:10

Andez