Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFr

ID: 3652253 • Letter: I

Question


import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class MainGUI extends JFrame {

private static final long serialVersionUID = 1L;
private JPanel contentPanel = null;

/**
* @param args
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MainGUI mainGUI = new MainGUI();
mainGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainGUI.setVisible(true);
}
});
}

/**
* default constructor
*/
public MainGUI() {
super();
initialize();
}

/**
* initializes
*
* @return void
*/
private void initialize() {
this.setSize(200, 400);
contentPanel = new JPanel();
JLabel label = new JLabel("Enter the number of courses");
contentPanel.add(label);
JButton btnRun = new JButton("Run");
contentPanel.add(btnRun);
this.setContentPane(contentPanel);
this.setTitle("Welcome Home!");
}


}

Explanation / Answer

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class MainGUI extends JFrame {

    private static final long serialVersionUID = 1L;
    private JPanel contentPanel = null;

    /**
     * @param args
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                MainGUI mainGUI = new MainGUI();
                mainGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                mainGUI.setVisible(true);
            }
        });
    }

    /**
     * default constructor
     */
    public MainGUI() {
        super();
        initialize();
    }

    /**
     * initializes
     *
     * @return void
     */
    private void initialize() {
        this.setSize(200, 400);
        contentPanel = new JPanel();
        JLabel label = new JLabel("Enter the number of courses");
        contentPanel.add(label);
        JButton btnRun = new JButton("Run");
        contentPanel.add(btnRun);
        this.setContentPane(contentPanel);
        this.setTitle("Welcome Home!");
    }


}

================================================

Sample output: