SteamPlayer
SteamPlayer

Reputation: 13

Make method that returns a JOptionPane.showMessageDialog with specified message?

What I am trying to ask here is this:

I've been typing JOptionPane.showMessageDialog, etc etc, all the time. So, I thought that I could make a method to make it shorter and easier, in this case named msgDialog().

public static String msgDialog(String message){
    return JOptionPane.showMessageDialog(null, message);
}

Why wouldn't this work? (error: cannot return a void result.)

Upvotes: 0

Views: 2099

Answers (2)

Piotr Bryla
Piotr Bryla

Reputation: 41

Try to change method type to void :

public static void msgDialog(String message){
        JOptionPane.showMessageDialog(null, message);
}

Upvotes: 1

dumbPotato21
dumbPotato21

Reputation: 5695

JOptionPane#showMessageDialog doesn't return anything. Thus, You can do this instead

public static void show(String s){
    JOptionPane.showMessageDialog(null, s);
}

Upvotes: 2

Related Questions