Issue ended up not being what I thought. Final comments give correct answer...
I'm trying to get a program to input employee information, and output the information when asked.
By hitting "New Employee" on a custom showOptionDialog button, the user would be prompted to enter information about the employee.
By hitting "Retrieve Information", the user would be able to retrieve the information by inputting the Employee's name or number. (this part has not been implemented yet in my code, however)
import javax.swing.*;
import java.awt.*;
public class InputList {
public static void main(String[] args) {
JFrame frame = new JFrame("EmployeeDatabase");
Object[] options = {
"New Employee",
"Retrieve Information"
};
int selectedValue = JOptionPane.showOptionDialog(
null,
"Select an option",
"Employee Database",
JOptionPane.DEFAULT_OPTION,
JOptionPane.PLAIN_MESSAGE,
null,
options,
options[0]
);
if(selectedValue == 0) {
String inputStringName = JOptionPane.showInputDialog(
"Employee Name",
"Last Name, First Name"
);
String inputStringIdentificationNumber = JOptionPane.showInputDialog(
"Employee Number",
"---"
);
String inputStringAge = JOptionPane.showInputDialog(
"Employee Age",
"--"
);
String inputStringWorkLevel = JOptionPane.showInputDialog(
"Reported Employee Skill Level",
"1 - Best : 20 - Worst"
);
if(inputStringName == null) {
return;
}
String employeeName = inputStringName;
String employeeIDNumber = inputStringIdentificationNumber;
String employeeAge = inputStringAge;
String employeeWorth = inputStringWorkLevel;
JOptionPane.showMessageDialog(
null,
employeeIDNumber
+ "\n"
+ employeeName
+ "\n"
+ employeeAge
+ " years old"
+ "\nRating: "
+ employeeWorth,
"Employee Information",
JOptionPane.PLAIN_MESSAGE
);
} else if(selectedValue == 1) {
JOptionPane.showMessageDialog(
null,
"Program Incomplete",
JOptionPane.PLAIN_MESSAGE
);
}
}
}
So, I have my custom "New Employee" and "Retrieve Information" buttons, as set up first.
I attempted to create a showOptionDialog, but every time I do, I get this error message:
InputList.java:75: error: no suitable method found for showMessageDialog(<null>,String,int)
JOptionPane.showMessageDialog(
^
method JOptionPane.showMessageDialog(Component,Object) is not applicable
(actual and formal argument lists differ in length)
method JOptionPane.showMessageDialog(Component,Object,String,int) is not applicable
(actual and formal argument lists differ in length)
method JOptionPane.showMessageDialog(Component,Object,String,int,Icon) is not applicable
(actual and formal argument lists differ in length)
1 error
I've attempted to replace the first null with frame, but I can't seem to understand how to use JFrame with JDialog and JOptionPane, as told to use by the Java API... any help is appreciated.
Since comments won't work properly:
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
This is the stencil I'm attempting to use
and this is the information that's messing me up:
The JOptionPane constructors do not include this argument. Instead, you specify the parent frame when you create the JDialog that contains the JOptionPane, and you use the JDialog setLocationRelativeTo method to set the dialog position.