Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
82Activity
0 of .
Results for:
No results containing your search query
P. 1
Java Tutorial Swing

Java Tutorial Swing

Ratings:

4.67

(6)
|Views: 4,227|Likes:
Published by viniciuspc

More info:

Published by: viniciuspc on Aug 22, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

04/15/2013

pdf

text

original

 
JAVA – SUN tutorial
Creating a GUI withJFC/Swing
 
1
 
Trail
: Creating a GUI with JFC/Swing
Lesson
: Using Swing Components
How to Make Dialogs
Several classes support
dialogs
 —windows that are more limited than frames.To create simple, standard dialogs, you use the 
 class. The 
 class can put up a dialog thatshows the progress of an operation. Two other classes, 
 and 
,alsosupply standard dialogs. To bring up a print dialog, you can use either the
getPrintJob
method definedin the 
 class or, if you’re using the Java 2 platform, thePrintingAPI. To create custom dialogs, use the
class directly.
The code for simple dialogs can be minimal. For example, here’s aninformational dialog:
Here is the code that creates and shows it:
JOptionPane.showMessageDialog(frame, “Eggs aren’tsupposed to be green.”);
The rest of this section covers the following topics:
An Overview of Dialogs
Every dialog is dependent on a frame. When that frame is destroyed, so are its dependent dialogs. Whenthe frame is iconified, its dependent dialogs disappear from the screen. When the frame is deiconified, itsdependent dialogs return to the screen. The AWT automatically provides this behavior.
A dialog can be
modal 
. When a modal dialog is visible, it blocks user inputto all other windows in the program. The dialogs that
JOptionPane
providesare modal. To create a non-modal dialog, you must use the
JDialog
classdirectly.The
JDialog
class is a subclass of the AWT 
class. Itadds to
Dialog
aroot paneand support for a default close operation. Theseare the same features that
JFrame
has, and using
JDialog
directly is verysimilar to using
JFrame
directly. If you’re going to use
JDialog
directly,
2
 
then you should understand the material inUsing Top-Level ContainersandHow to Make Frames, especiallyResponding to Window-Closing Events. Even when you use
JOptionPane
to implement a dialog, you’re still using a
JDialog
behind the scenes. The reason is that
JOptionPane
is simply acontainer that can automatically create a
JDialog
and add itself to the
JDialog
s content pane.
The DialogDemo Example
Here’s a picture of an application that displays dialogs.
JOptionPane Features
Using
JOptionPane
, you can create and customize several different kinds of dialogs.
JOptionPane
 provides support for laying out standard dialogs, providing icons, specifying the dialog’s title and text, andcustomizing the button text. Other features allow you to customize the components the dialog displays andspecify where the dialog should appear onscreen. You can even specify that an option pane put itself intoan internal frame (
JInternalFrame
) instead of a
JDialog
.
Note:
The internal frames that
JOptionPane
creates currently behave differently from modal dialogs.They don’t behave modally, and in general seem more like frames than like dialogs. For this reason, wedon’t currently recommend their use.
When you create a
JOptionPane
, look-and-feel-specific code addscomponents to the
JOptionPane
and determines the layout of thosecomponents.
JOptionPane
s icon support lets you easily specify which icon the dialogdisplays. You can use a custom icon, no icon at all, or any one of four standard
JOptionPane
icons (question, information, warning, and error).Each look and feel has its own versions of the four standard icons. Thefollowing figure shows the icons used in the Java Look & Feel.
Icons provided by JOptionPane
3

Activity (82)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
hockchilato liked this
kerbel liked this
Rajesh Vhadlure liked this
mdharma; liked this
ALi liked this
ALi liked this
Jojo Cansino liked this
emrullah60 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->