Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to display JOptionPane on button click

I am trying to make a JOptionPane display on button click but I keep getting an error saying I’m missing a return statement in my constructor. Any help would be really appreciated. Thanks
This is my code so far.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

public class lab9Part1 extends JFrame implements ActionListener {
    JButton button = new JButton("Show Message Dialog");
    JFrame box = new JFrame();

    public lab9Part1() {
        super("lab9Part1");
        Container c = getContentPane();
        button.addActionListener(this);
        c.add(button, BorderLayout.SOUTH);
        setVisible(true);
        setSize(500,500);
    }

    public static Void main (String [] args){
        JFrame frame = new lab9Part1();
    }

    public void actionPerformed(ActionEvent e){
        if (e.getSource()== button) {
            JOptionPane.showMessageDialog(box,"hello","This is Cal and this is my first message dialog", JOptionPane.INFORMATION_MESSAGE);
        }
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’ve used Void (uppercase V) instead of void (lowercase v) in your method declaration of main. It should be:

 public static void main (String [] args){

        JFrame frame = new lab9Part1();

 }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading