Re: showInputDialog method
never mind .. i solved it this way..
i saw a sample of inputDialog in the internet
and i analyze how does it happen to be fine (not displaying an exception) , when a user press the cancel button
heres the code that i made from the one that i got in the net... this might help others regarding with inputDialog
Code :
public static void main(String[] args) {
String x = (String) JOptionPane.showInputDialog(null, "Press The Cancel!");
if (x == null) {
System.out.println("Theres No NumberFormatException Anymore!");
}
}
}
now my question is about the code that ive got
heres the code that ive got in the internet about inputDialog
Code :
public class ComboBoxShowInputDialog
{
public static final String[] pizzas = { "Cheese", "Pepperoni", "Sausage", "Veggie",
"Keso", "Tuna", "Baboy"};
public static void main(String[] args)
{
JFrame frame = new JFrame("Input Dialog Example 3");
String favoritePizza = (String) JOptionPane.showInputDialog(frame, "What is your favorite pizza?", "Favorite Pizza", JOptionPane.QUESTION_MESSAGE, null, pizzas, null);
// favoritePizza will be null if the user clicks Cancel
System.out.printf("Favorite pizza is %s.\n", favoritePizza);
System.exit(0);
}
}
im using the System class together with .print() .prntln() methods..
but i didnt knew theres another print method signatured as
whats the purpose of this method? in my opinion.. this one accepts and displays objects.. (thats the only thing i notice about it),
Re: showInputDialog method
printf is a "remenant" that's quite useful from the C/C++ languages (actually, a lot of programming languages has it). It basically stands for "print formatted". You can format how you want the output displayed.
ex: say you want to display a double with 2 decimal places:
Code :
System.out.printf("%.2f",123.456789);
The reason it's in these other languages is because they don't automatically concatenate strings together like in Java:
Code :
System.out.print("The answer is " + 123.456789 + " meters");
Code :
printf("The answer is %f meters", 123.456789);
Java also has a number formatting class if you don't want to use the printf method and want to format it in different ways.