Transcription

Creating a GUI with JFC/SwingThe JavaTM TutorialStart of TutorialSearchFeedback FormExamples IndexTrail: Creating a GUI with JFC/SwingThe Creating a GUI with JFC/Swing trail tells you how to create graphical userinterfaces (GUIs) for applications and applets, using the Swing components. The Swingcomponents, which are part of the JavaTM Foundation Classes (JFC), can be used witheither JDKTM 1.1 or the JavaTM 2 platform.Note: This trail does not tell you how to use the AWT components. If youneed to write a JDK 1.0 program or a 1.1 program that doesn't use Swingcomponents, please download the old UI trail, Creating a User Interface(AWT Only).This trail is available as a book, The JFC Swing Tutorial .Besides having the usual advantages of a book (such asportability and readability) this 950-page tome contains a CDthat has API documentation, the JFC 1.1 and JDK 1.1 releases,the latest available releases of the Java 2 SDK, and lots of othergoodies.A shorter, simpler introduction to using the Swing components is publishedin the book The Java Tutorial, 3rd Edition . You can find it online here:User Interfaces that Swing: A Quick Start Guide.Getting Started with Swing is a quick start lesson. First it gives you a bit ofbackground about the JFC and Swing. Then it tells you how to compile and runprograms -- both applications and applets -- that use Swing components. Finally, it walksyou through the code for a simple program.Swing Features and Concepts gives you the information you need to be able to useSwing components effectively. For example, it tells you how Swing programs displaytheir GUIs, how they handle events such as mouse clicks, and how they can use swing/index.html (1 of 3) [10/28/2001 1:51:25 PM]

Creating a GUI with JFC/Swingsuch as borders to help with layout. It ends with a discussion of how the features andconcepts are used by a real program.Using Swing Components tells you how to use each of the Swing components -buttons, tables, text components, and all the rest.Using Other Swing Features tells you how to use actions, borders, icons, and timers.It also helps you to create multithreaded programs.Laying Out Components Within a Container tells you how to choose a layoutmanager, how to use each of the layout manager classes the JavaTM platform provides,how to use absolute positioning instead of a layout manager, and how to create your ownlayout manager.Writing Event Listeners tells you how to handle events in your programs.Working with Graphics tells you how to do everything from drawing lines and textto loading, displaying, and manipulating images. It includes information onperforming animation and on improving graphics performance.Converting to Swing tells you how to convert programs that use the 1.1 AWT API touse the Swing components.Although this is the main trail for learning about GUIs, it isn't the only trail with UI-relatedinformation. Here are some other trails that discuss UI topics: 2D Graphics , which describes the 2D graphics features available in the Java 2platform.Sound , which discusses the sound capabilities available in the Java 2 platform.Writing Applets , which describes API available only to applets, such as soundcapabilities in JDK 1.0 and 1.1.Essential Java Classes , which covers many topics, including properties and thestandard I/O streams.The Bonus trail contains Full-Screen Exclusive Mode API , a lesson that describeshow to use API introduced in v1.4 to render graphics directly to the screen.Your feedback is important to us! Please send your comments andsuggestions to us using the feedback ng/index.html (2 of 3) [10/28/2001 1:51:25 PM]

Creating a GUI with JFC/SwingStart of TutorialCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/index.html (3 of 3) [10/28/2001 1:51:25 PM]SearchFeedback FormExamples Index

Creating a GUI with JFC/Swing: Table of ContentsThe JavaTM TutorialStart of Tutorial Start of TrailSearchFeedback FormExamples IndexTrail: Creating a GUI with JFC/Swing: Table ofContentsUser Interfaces that Swing: A Quick Start GuideOverview of the Swing APIYour First Swing ProgramExample Two: SwingApplicationExample Three: CelsiusConverterExample Four: LunarPhasesExample Five: VoteDialogLayout ManagementThreads and SwingSummaryQuestions and Exercises: User Interfaces That SwingGetting Started with SwingAbout the JFC and SwingCompiling and Running Swing ProgramsCompiling and Running Swing Programs (Java 2 Platform)Compiling and Running Swing Programs (JDK 1.1)Running Swing AppletsA Quick Tour of a Swing Application's CodeSwing Features and ConceptsSwing Components and the Containment HierarchyLayout ManagementEvent HandlingPaintingThreads and SwingMore Swing Features and ConceptsThe Anatomy of a Swing-Based wing/TOC.html (1 of 5) [10/28/2001 1:51:26 PM]

Creating a GUI with JFC/Swing: Table of ContentsUsing Swing ComponentsA Visual Index to the Swing ComponentsThe JComponent ClassUsing Top-Level ContainersHow to Make Frames (Main Windows)How to Make DialogsHow to Make AppletsUsing Intermediate Swing ContainersHow to Use PanelsHow to Use Scroll PanesHow to Use Split PanesHow to Use Tabbed PanesHow to Use Tool BarsHow to Use Internal FramesHow to Use Layered PanesHow to Use Root PanesUsing Atomic ComponentsHow to Use Buttons, Check Boxes, and Radio ButtonsHow to Use Color ChoosersHow to Use Combo BoxesHow to Use File ChoosersHow to Use LabelsHow to Use ListsHow to Use MenusHow to Monitor ProgressHow to Use SlidersHow to Use TablesUsing Text ComponentsAn Example of Using Each Text ComponentGeneral Rules for Using Text ComponentsHow to Use Text FieldsConcepts: About Editor Panes and Text PanesSummary of TextHow to Use Tool TipsHow to Use TreesSolving Common Component ProblemsUsing Other Swing swing/TOC.html (2 of 5) [10/28/2001 1:51:26 PM]

Creating a GUI with JFC/Swing: Table of ContentsHow to Use ActionsHow to Support Assistive TechnologiesHow to Use BordersHow to Use IconsHow to Set the Look and FeelHow to Use ThreadsHow to Use TimersSolving Common Problems Using Other Swing FeaturesLaying Out Components Within a ContainerUsing Layout ManagersGeneral Rules for Using Layout ManagersHow to Use BorderLayoutHow to Use BoxLayoutHow to Use SpringLayoutHow to Use CardLayoutHow to Use FlowLayoutHow to Use GridLayoutHow to Use GridBagLayoutHow to Use GridBagLayout: Specifying ConstraintsHow to Use GridBagLayout: The Example ExplainedCreating a Custom Layout ManagerDoing Without a Layout Manager (Absolute Positioning)Solving Common Layout ProblemsWriting Event ListenersSome Simple Event-Handling ExamplesGeneral Information about Writing Event ListenersListeners Supported by Swing ComponentsImplementing Listeners for Commonly Handled EventsHow to Write an Action ListenerHow to Write a Caret ListenerHow to Write a Change ListenerHow to Write a Component ListenerHow to Write a Container ListenerHow to Write a Document ListenerHow to Write a Focus ListenerHow to Write an Internal Frame swing/TOC.html (3 of 5) [10/28/2001 1:51:26 PM]

Creating a GUI with JFC/Swing: Table of ContentsHow to Write an Item ListenerHow to Write a Key ListenerHow to Write a List Data ListenerHow to Write a List Selection ListenerHow to Write a Mouse ListenerHow to Write a Mouse-Motion ListenerHow to Write a Table Model ListenerHow to Write a Tree Expansion ListenerHow to Write a Tree Model ListenerHow to Write a Tree Selection ListenerHow to Write a Tree-Will-Expand ListenerHow to Write an Undoable Edit ListenerHow to Write a Window ListenerSummary of Listener APISolving Common Event-Handling ProblemsWorking with GraphicsOverview of Custom PaintingUsing Graphics PrimitivesPainting ShapesWorking with TextUsing ImagesLoading ImagesDisplaying ImagesPerforming AnimationCreating an Animation Loop with TimerMoving an Image Across the ScreenDisplaying a Sequence of ImagesImproving the Appearance and Performance of Image AnimationSolving Common Graphics ProblemsConverting to SwingWhy to ConvertHow to ConvertConversion ResourcesSwing Replacements for AWT ComponentsGeneral Conversion TipsComponent-Specific Conversion g/TOC.html (4 of 5) [10/28/2001 1:51:26 PM]

Creating a GUI with JFC/Swing: Table of ContentsSome Conversion ExamplesSolving Common Conversion ProblemsStart of Tutorial Start of TrailCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/TOC.html (5 of 5) [10/28/2001 1:51:26 PM]SearchFeedback FormExamples Index

Creating a GUI with JFC/Swing: Indexes of ExamplesThe JavaTM TutorialStart of Tutorial Start of TrailSearchFeedback FormTrail: Creating a GUI with JFC/Swing: Indexes ofExamplesGetting Started with Swing: ExamplesSwing Features and Concepts: ExamplesUsing Swing Components: ExamplesUsing Other Swing Features: ExamplesLaying Out Components: ExamplesWriting Event Listeners: ExamplesWorking with Graphics: ExamplesConverting to Swing: ExamplesStart of Tutorial Start of TrailCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/examples.html [10/28/2001 1:51:27 PM]SearchFeedback Form

Getting Started with Swing: ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Getting Started with SwingGetting Started with Swing: ExamplesNote: Examples are applets unless noted otherwise.Source FilesImage & Other FilesWhereDescribedAppletDemo.javaright.gif, middle.gif,left.gifTo run the applet:AppletDemo.htmlTo view the APPLET plet.javaTo run the applet:HelloSwingApplet.htmlTo view the APPLET pplication.javaapplication)(anStart of Tutorial Start of Trail Start of LessonCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/start/example-swing/index.html [10/28/2001 1:51:27 PM]CompilingandRunningSwingProgramsSearchFeedback Form

Swing Features and Concepts: ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Swing Features and ConceptsSwing Features and Concepts: ExamplesNote: Examples are applications unless noted otherwise.Image & OtherFilesSource avaFormattedDocument.javaUnit.javaWhere DescribedThe Anatomy of a SwingBased ProgramStart of Tutorial Start of Trail Start of LessonCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/overview/example-swing/index.html [10/28/2001 1:51:28 PM]SearchFeedback Form

Using Swing Components: ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Using Swing ComponentsUsing Swing Components: ExamplesNote: Examples are applications unless noted otherwise.For most examples, place the image files in a directory named images in the samedirectory as the source and class files for the example. For example, here's the setup forButtonDemo:Some examples, such as CheckBoxDemo and SliderDemo, require the image files tobe in a sub-directory of the images directory.Source FilesImage & Other FilesWhereDescribedButtonDemo.javaright.gif, middle.gif,left.gifHow to UseButtons, .CheckBoxDemo.javaAll of the images in theimages/geek directory.How to UseButtons, .html (1 of 7) [10/28/2001 1:51:29 PM]How to UseColorChoosers

Using Swing Components: gif, yellow.gif,green.gif, blue.gifHow to UseColorChoosersComboBoxDemo.javaBird.gif, Cat.gif,Dog.gif, Rabbit.gif,Pig.gifHow to UseComboBoxesHow to javaBird.gif, Cat.gif,Dog.gif, Rabbit.gif,Pig.gifHow to e.gifHow to UseDialogsDynamicTreeDemo.javaDynamicTree.javaHow to UseTreesFileChooserDemo.javaopen.gif, save.gifHow to javaImageFilter.javaImagePreview.javaUtils.javaHow to UsejpgIcon.gif, How vaHow to UseTreesGlassPaneDemo.javaHow to UseRoot ng/components/example-swing/index.html (2 of 7) [10/28/2001 1:51:29 PM]

Using Swing Components: ExamplesHtmlDemo.javaHow to aHow to aLayeredPaneDemo2.javamiddle.gifHow to UseLabelsdukeWaveRed.gifHow to UseLayeredPanesdukeWaveRed.gifHow to UseLayeredPanesListDemo.javaHow to UseListsListDialog.javaHow to UseButtons, .MenuLookDemo.javamiddle.gifHow to UseMenusMenuDemo.javamiddle.gifHow to UseMenusMenuGlueDemo.javaHow to UseMenusMenuLayoutDemo.javaHow to UseMenusPasswordDemo.javaHow to UseText swing/index.html (3 of 7) [10/28/2001 1:51:29 PM]How to UseMenusHow toMonitorProgress

Using Swing Components: ExamplesHow javaSwingWorker.javaRadioButtonDemo.javaBird.gif, Cat.gif,Dog.gif, Rabbit.gif,Pig.gifHow to UseButtons, ure.javayoungdad.jpegHow to UseScroll PanesScrollDemo2.javaHow to UseScroll vaHow to UseTablesSimpleTableSelectionDemo.javaHow to UseTablesSliderDemo.javaAll of the images in theimages/doggy directory.How to UseSlidersSliderDemo2.javaAll of the images in theimages/doggy directory.How to UseSlidersSplitPaneDemo.javaimagenames.properties and How to Useall of the image files listed in it.Split PanesSplitPaneDemo2.javaimagenames.properties and How to Useall of the image files listed in it.Split PanesTabbedPaneDemo.javaHow to UseTabbedPanesmiddle.gifTableDemo.javaHow to w to javaHow to iswing/components/example-swing/index.html (4 of 7) [10/28/2001 1:51:29 PM]

Using Swing Components: ExamplesTableRenderDemo.javaHow to ter.javaHow to nt.javaGeneralRules forUsing TextComponentsTextDemo.java(an applet)To run the applet:TextDemo.htmlTo view the APPLET vaFormattedDocument.javaWholeNumberField.javaHow to UseText FieldsHow to UseText FieldsTextSamplerDemo.javaAn ExamplePig.gif, sound.gif,of UsingdukeWaveRed.gif,Each avaright.gif, middle.gif,left.gifHow to UseTool BarsToolBarDemo2.javaright.gif, middle.gif,left.gifHow to UseTool BarsUsing veral html files.How to UseTreesTreeIconDemo.javamiddle.gif and several htmlfiles.How to UseTreesTreeIconDemo2.javamiddle.gif and several htmlfiles.How to swing/components/example-swing/index.html (5 of 7) [10/28/2001 1:51:29 PM]

Using Swing Components: ExamplesTumbleItem.java (an applet)SwingWorker.javaAll of the images in theimages/tumble directory.To run the applet:TumbleItem.htmlTo view the APPLET tag:TumbleItem.atagHow toMakeAppletsGeek Imagesgeek-----.gif, geek-c---.gif, geek--g--.gif, geek---h-.gif,geek----g.gif, geek-cg--.gif, geek-c-h-.gif, geek-c--t.gif,geek--gh-.gif, geek--g-t.gif, geek---h-.gif, geek-cg-t.gif,geek-cgh-.gif, geek-c-ht.gif, geek--ght.gif, geek-cght.gifDoggy ImagesT0.gif, T1.gif, T2.gif, T3.gif, T4.gif, T5.gif, T6.gif,T7.gif, T8.gif, T9.gif, T10.gif, T11.gif, T12.gif, T13.gifTumble ImagesT1.gif, T2.gif, T3.gif, T4.gif, T5.gif,T6.gif, T7.gif, T8.gif, T9.gif, T10.gif,T11.gif, T12.gif, T13.gif, T14.gif, T15.gif,T16.gif, T17.gifImages listed in imagenames.propertiesBird.gif, Cat.gif, Dog.gif, Rabbit.gif, Pig.gif,all.gif, blue.gif, doggy/T1.gif, dukeWaveRed.gif, geek/geekcght.gif,green.gif, kathyCosmo.gif, lainesTongue.gif, left.gif, middle.gif,red.gif, right.gif, smallbabies.jpeg, sophie.gif, stickerface.gif,tumble/T7.gif, yellow.gif, youngdad.jpeg,HTML Files Required for Tree ng/components/example-swing/index.html (6 of 7) [10/28/2001 1:51:29 PM]

Using Swing Components: htmlthread.htmlvm.htmljls.htmlStart of Tutorial Start of Trail Start of LessonSearchFeedback FormCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/components/example-swing/index.html (7 of 7) [10/28/2001 1:51:29 PM]

Using Other Swing Features: ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Using Other Swing FeaturesUsing Other Swing Features: ExamplesNote: Examples are applications unless noted otherwise.For all examples, place the image files in a directory named images in the same directoryas the source and class files for the example. For example, here's the setup forActionDemo:Image & Other ow .gif, middle.gif, How to UseActionsleft.gifBorderDemo.javaleft.gifHow to gifHow to UseIconsSource ng/misc/example-swing/index.html (1 of 2) [10/28/2001 1:51:30 PM]

Using Other Swing Features: avaright.gif, e.gif,(an applet) lainesTongue.gif,kathyCosmo.gif,ewanPumpkin.gif,To run the applet:IconDemoApplet.htmlTo view the APPLET tag:IconDemoApplet.atagStart of Tutorial Start of Trail Start of LessonCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/misc/example-swing/index.html (2 of 2) [10/28/2001 1:51:30 PM]How to UseIconsSearchFeedback Form

Laying Out Components: ExamplesThe JavaTM TutorialSearchFeedback FormStart of Tutorial Start of Trail Start of LessonTrail: Creating a GUI with JFC/SwingLesson: Laying Out ComponentsLaying Out Components: ExamplesNote: The examples listed here can run either as an application or as anapplet unless noted otherwise.Source FilesImage & Other FilesWhere DescribedAlignmentDemo.java(application only)geek-cght.gifmiddle.gifHow to UseBoxLayoutBorderWindow.javaAppletButton.javaTo run the applet:How to UseBorderDemo.htmlTo view the APPLET tag: ication only)BLDComponent.javaHow to UseBoxLayoutBoxWindow.javaAppletButton.javaTo run the applet:How to UseBoxDemo.htmlTo view the APPLET tag: avaTo run the applet:How to UseCardDemo.htmlTo view the APPLET tag: yout.javaAppletButton.javaTo run the applet:How to UseCustomDemo.htmlTo view the APPLET tag: x.html (1 of 2) [10/28/2001 1:51:31 PM]

Laying Out Components: ExamplesFlowWindow.javaAppletButton.javaTo run the applet:How to UseFlowDemo.htmlTo view the APPLET tag: ton.javaTo run the applet:How to UseGridBagDemo.htmlTo view the APPLET tag: Button.javaTo run the applet:How to UseGridDemo.htmlTo view the APPLET tag: .javaTo run the applet:NoneDemo.htmlTo view the APPLET tag:NoneDemo.atagTabWindow.javaAppletButton.javaTo run the applet:How to UseTabDemo.htmlTo view the APPLET tag: CardLayoutTabDemo.atagDoing Without aLayout Manager(AbsolutePositioning)Start of Tutorial Start of Trail Start of LessonCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/layout/example-swing/index.html (2 of 2) [10/28/2001 1:51:31 PM]SearchFeedback Form

Writing Event Listeners: ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Writing Event ListenersWriting Event Listeners: ExamplesNote: Examples are applets unless noted otherwise.Image & Other FilesWhereDescribedBeeper.javaTo run the applet: Beeper.htmlTo view the APPLET onentEventDemo.javaTo run the applet:ComponentEventDemo.htmlTo view the APPLET tag:ComponentEventDemo.atagHow toWrite aComponentListenerContainerEventDemo.javaTo run the applet:ContainerEventDemo.htmlTo view the APPLET tag:ContainerEventDemo.atagHow toWrite aContainerListenerDocumentEventDemo.javaTo run the applet:DocumentEventDemo.htmlTo view the APPLET tag:DocumentEventDemo.atagHow toWrite aDocumentListenerFocusEventDemo.javaTo run the applet:FocusEventDemo.htmlTo view the APPLET tag:FocusEventDemo.atagHow toWrite aFocusListenerSource ng/events/example-swing/index.html (1 of 3) [10/28/2001 1:51:32 PM]

Writing Event Listeners: ExamplesKeyEventDemo.javaTo run the applet:KeyEventDemo.htmlTo view the APPLET tag:KeyEventDemo.atagHow toWrite aKeyListenerListDataEventDemo.javaup.gif, down.gifTo run the applet:ListDataEventDemo.htmlTo view the APPLET tag:ListDataEventDemo.atagHow toWrite aList DataListenerListSelectionDemo.javaapplication)How toWrite aListSelectionListener(anHow toWrite an application)How toWrite aMouseListenerMouseEventDemo.javaBlankArea.javaTo run the applet:MouseEventDemo.htmlTo view the APPLET ankArea.javaHow toTo run the applet:Write aMouseMotionEventDemo.htmlMouseTo view the APPLET stener.javaTo run the applet:MultiListener.htmlTo view the APPLET l (2 of 3) [10/28/2001 1:51:32 PM]SomeSimpleEventHandlingExamples

Writing Event Listeners: ExamplesHow toWrite aTreeExpansionListenerTreeExpandEventDemo.javaTo run the applet:TreeExpandEventDemo.htmlTo view the APPLET avaHow toTo run the applet:Write aTreeExpandEventDemo2.htmlTree WillTo view the APPLET ventDemo.javaTo run the applet:WindowEventDemo.htmlTo view the APPLET tag:WindowEventDemo.atagStart of Tutorial Start of Trail Start of LessonCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/events/example-swing/index.html (3 of 3) [10/28/2001 1:51:32 PM]How toWrite aWindowListenerSearchFeedback Form

Working with Graphics: ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Working with GraphicsWorking with Graphics: ExamplesNote: Examples are applets unless noted otherwise.Source FilesImage & Other FilesWhereDescribedAnimatorAppletTimer.javaTo run the applet:AnimatorAppletTimer.htmlTo view the APPLET tag:AnimatorAppletTimer.atagCreating anAnimationLoop withTimerCreating anAnimationLoop withTimerAnimatorApplicationTimer.java(an application)CoordinatesDemo.javaTo run the applet:CoordinatesDemo.htmlTo view the APPLET tag:CoordinatesDemo.atagOverview ofCustomPaintingFontDemo.javaTo run the applet:FontDemo.htmlTo view the APPLET tag:FontDemo.atagWorkingwith TextImageDisplayer.javarocketship.gifTo run the applet:ImageDisplayer.htmlTo view the APPLET tag:ImageDisplayer.atagOverview orial/uiswing/painting/example-swing/index.html (1 of 3) [10/28/2001 1:51:32 PM]

Working with Graphics: ExamplesImageSequenceTimer.javaSeveral images.To run the applet:ImageSequenceTimer.htmlTo view the APPLET vaImprovingtheSeveral images.AppearanceTo run the applet:MTImageSequenceTimer.html andTo view the APPLET tag:PerformanceMTImageSequenceTimer.atag of starfield.gifTo run the applet:MovingImageTimer.htmlTo view the APPLET tag:MovingImageTimer.atagMoving anImageAcross .gifTo run the applet:MovingLabels.htmlTo view the APPLET tag:MovingLabels.atagMoving anImageAcross theScreenRectangleDemo.javaTo run the applet:RectangleDemo.htmlTo view the APPLET javastarfield.gifTo run the applet:SelectionDemo.htmlTo view the APPLET tag:SelectionDemo.atagOverview ofCustomPaintingShapesDemo.javaTo run the applet:ShapesDemo.htmlTo view the APPLET ing/index.html (2 of 3) [10/28/2001 1:51:32 PM]Displaying aSequence ofImages

Working with Graphics: ExamplesTextXY.javaTo run the applet: TextXY.htmlTo view the APPLET tag:TextXY.atagWorkingwith TextAnimation ImagesT1.gif, T2.gif, T3.gif, T4.gif, T5.gif,T6.gif, T7.gif, T8.gif, T9.gif, T10.gifStart of Tutorial Start of Trail Start of LessonCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/painting/example-swing/index.html (3 of 3) [10/28/2001 1:51:32 PM]SearchFeedback Form

Converting to Swing: ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Converting to SwingConverting to Swing: ExamplesNote: Examples are applications unless noted otherwise. Refer toConverting to Swing: AWT-Based Examples for the AWT-basedequivalents of these examples.Source FilesImage & Other nversionExamplesButtonDemoApplet.javaright.gif, middle.gif,left.gifSomeTo run the applet:Conversion(an applet)ButtonDemoApplet.htmlExamplesTo view the APPLET g/converting/example-swing/index.html (1 of 2) [10/28/2001 1:51:33 PM]SomeConversionExamples

Converting to Swing: vaTextEventDemo.java(an applet)To run the applet:TextEventDemo.htmlTo view the APPLET tag:TextEventDemo.atagStart of Tutorial Start of Trail Start of LessonSomeConversionExamplesSearchFeedback FormCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/converting/example-swing/index.html (2 of 2) [10/28/2001 1:51:33 PM]

Converting to SwingThe JavaTM TutorialStart of Tutorial Start of TrailSearchFeedback FormExamples IndexTrail: Creating a GUI with JFC/SwingLesson: Converting to SwingThis lesson tells you how to convert your AWT-based programs to use the Swingcomponents. If a program was written for JDK 1.0 -- meaning that instead of using theevent listening system introduced in JDK 1.1, it uses methods such as handleEvent andaction -- you should convert the program to the newer event system first. Refer toMigrating to 1.1 for information and instructions on updating 1.0 programs.Why to ConvertSwing components provide many benefits to programmers and end users. For a list ofSwing features, see Swing Features and Concepts . Another good resource is the HowAre Swing Components Different from AWT Components? section. Unless you have agood reason not to convert, we urge you to convert to Swing components as soon aspossible.How to ConvertThis section outlines a procedure for converting your programs to Swing. The good newsis that converting 1.1 AWT-based programs to Swing can be pretty straightforward. Thebad news is that we don't know of any automatic tools for doing so. If you find one, pleasetell us. Click the Creating a GUI with JFC/Swing radio button in Step 2.Conversion ResourcesThis section provides several resources to help you with your conversion, includingexamples.Solving Common Conversion ProblemsLike the name says, this section lists some common gotchas, along with their uiswing/converting/index.html (1 of 2) [10/28/2001 1:51:33 PM]

Converting to SwingStart of Tutorial Start of TrailCopyright 1995-2001 Sun Microsystems, Inc. All rights iswing/converting/index.html (2 of 2) [10/28/2001 1:51:33 PM]SearchFeedback FormExamples Index

Converting to Swing: AWT-Based ExamplesThe JavaTM TutorialStart of Tutorial Start of Trail Start of LessonSearchFeedback FormTrail: Creating a GUI with JFC/SwingLesson: Converting to Swin

the latest available releases of the Java 2 SDK, and lots of other goodies. A shorter, simpler introduction to using the Swing components is published in the book The Java Tutorial, 3rd Edition . You can find it online here: User Interfaces that Swing: A Quick Start Guide. Getting Started wit