Beruflich Dokumente
Kultur Dokumente
BufferedReader class
JOptionane class
BufferedReader class
!he lines,
indicate that "e "ant to use the classes BufferedReader,
0nput*treamReader and 0O12ception "hich are inside the
$ava%io package%
!he statement,
means "e declare a class named 4et0nput#rom5eyboard
!he statement,
declares a variable named dataIn, "ith the class type
BufferedReader%
)on6t "orry about "hat the synta2 means for no"% 7e "ill cover more about
classes and declaring classes later in the course%
Introduction to Programming 1 12
ample !rogram
String name = "";
System.out.print("Please Enter Your Name:");
!he statement,
declares a String variable "ith identifier name.
7e "ill cover more about e2ception handling in the latter part of this
course%
Introduction to Programming 1 14
ample !rogram
!his value "ill then be saved to our name variable, "hich "e
"ill use in our final statement to greet the user,
name = dataIn.readLine();
System.out.println("Hello " + name + "!");
Introduction to Programming 1 15
Using "option!ane Class
!he statement,
indicates that "e "ant to import the class JOptionane from
the $ava2%s"ing package%
!he statement,
creates a JOptionane input dialog, "hich "ill display a
dialog "ith a message, a te2tfield and an O5 button as
sho"n in the figure%
!he statement,
creates the "elcome message, "hich "e "ill store in the
msg variable%
Introduction to Programming 1 21
ample !rogram
JOptionPane.showMessageDialog(null, msg);
!he statement,
displays a dialog "hich contains a message and an O5
button%
Introduction to Programming 1 22
ummary
BufferedReader
JOptionane