package javaapplication1;
import javax.swing.JOptionPane;
public class Room{
public static void main(String[] args) {
dialog();
System.out.println(sample);
}
public static String dialog() {
String sample = JOptionPane.showInputDialog(null, "Insert Value", "Enter amount ", JOptionPane.QUESTION_MESSAGE);
if (sample.isEmpty()) {
JOptionPane.showMessageDialog(null, "Error!", "No Value Detected", JOptionPane.ERROR_MESSAGE);
dialog();
}
System.out.println(sample+" from the bottom line.");
return sample;
}
Hey guys,
it seems that I'm currently facing an issue with java at the moment in terms of calling one variable from another object. Following the code above, it's a sample code that provides the user input using java swing. I have 2 objects one being the main and one more being dialog(), dialog has declared a variable called sample that I want to bring it over to main, however I can't seem to use the variable as it always comes out an error.
Would appreciate some advice thanks!