From the past few lessons here, we are running JAVA programs in cmd/text only interfaces. Now we will learn how JOptionPane class in java works to have an object oriented program.
//import JOptionPane class
import javax.swing.JOptionPane;
public class Joptionpanejava {
public static void main(String[] args) {
//e main line for JOptionPane
JOptionPane.showMessageDialog(null,"WELCOME to magJAVAtayo!");
}
}
// showMesssageDialog method is under JOptionPane class and this method requires two arguments. If a method requiures multiple arguments, these must be separated by comma(,). And the first argument will always be the keyword null
JOptionPane.showMessageDialog(first argument , second argument);
Output should be like this:
If you want to print from user's input, edit the code to this.
// declare string variable
String string1;
//use showInputDialog method
string1=JOptionPane.showInputDialog("Ano ang pangalan mo?");
JOptionPane.showMessageDialog(null,"Hi "+string1+"! Kumusta?");
try this code to see the output.
More examples by request, basta kaya gawin ni author:)
More lessons to come.
If you have more something to add ikakagalak ko po.
SHARE and LEARN!
No comments:
Post a Comment