Hello Experts,
I need to use JOptionPane a lot in my Java exercises. Instead clustering each Java files with this JOptionPane syntax plus the parameters, I've decided to use sort of class called showFrame which has the method to show message dialog and input dialog. At the moment, im putting everything in one Java file since im still stuck. But once successful, then I'll put it in a separate java file. My problem is that, I duno how to invoke the methods in showFrame class. I did put it in my main method but generates compile error.
I want to be to call the showFrame constructor and the parameters is based on values set in the local method that call this constructor. The default value is initialized in the showFrame class (this value will be used if user does not pass any arguments in the local method that call the showFrame constructor.
Here is my coding:
Can someone point me in the right direction, please..
import javax.swing.*;
import java.lang.*;
public class Joption {
public class showFrame{
private String dialogTitle = "CCA";
private int styleInfo = 2; //INFORMATION_MESSAGE type
private String messageToUser = "";
private String showFrame = "null";
public void setDialogTitle(String dialogTitle)
{
this.dialogTitle = dialogTitle;
}
public String getDialogTitle()
{
return (this.dialogTitle);
}
public void setStyleInfo(int styleInfo)
{
this.styleInfo = styleInfo;
}
public int getStyleInfo()
{
return (this.styleInfo);
}
public void setMessageToUser(String messageToUser)
{
this.messageToUser= messageToUser;
}
public String getMessageToUser()
{
return (this.messageToUser);
}
public void setShowFrame(String showFrame)
{
this.showFrame= showFrame;
}
public String getShowFrame()
{
return (this.showFrame);
}
public void showMessageFrame(String showFrame, String messageToUser, String dialogTitle, int infoStyle)
{
JOptionPane.showMessageDialog(showFrame, messageToUser, dialogTitle, infoStyle);
}
public void showInputPrompt(String showFrame, String messageToUser, String dialogTitle, int infoStyle)
{
JOptionPane.showInputPrompt(showFrame, messageToUser, dialogTitle, infoStyle);
}
}
public static void main (String args[]) {
JOptionPane.showMessageDialog(null,"Eggs are not supposed to be green.", "Message", JOptionPane.INFORMATION_MESSAGE);
String input = JOptionPane.showInputDialog(null, "Please Enter a value", "hello", JOptionPane.QUESTION_MESSAGE);
JOptionPane.showMessageDialog(null, "You entered the following text: " + input , "User Input", JOptionPane.INFORMATION_MESSAGE);
}
}
Thanks