Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
My First Java Program
Exercise 1) Write the following code in to the java editor and see the output :
-----------------------------------------------------//This program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
------------------------------------------------------
Exercise 2) Displaying Text in a Message Dialog Box
i) Write the following code into the java editor and see the output :
-----------------------------------------------------------------------------------------//This program prints Welcome to Java! message in a message dialog box
import javax.swing.JOptionPane;
public class Welcome {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Welcome to Java!");
}
}
-----------------------------------------------------------------------------------------Two Ways to Invoke the Method
There are several ways to use the “showMessageDialog” method. For the time being, all you
need to know are two ways to invoke it.
1) One way is to use a statement like this:
JOptionPane.showMessageDialog(null, x);
where x is a string for the text to be displayed.
2) The other way is to use a statement as:
JOptionPane.showMessageDialog(null, x, y, JOptionPane.INFORMATION_MESSAGE);
where x is a string for the text to be displayed, and y is a string for the title of the message
dialog box.
ii) Write the code to invoke the “showMessageDialog” method by using the second way
and see the output in below :