Java Swing Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.00

JFrame - Main Frame Class

This chapter provides tutorial notes and example codes on JFrame class. Topics include creating frames with sizes and locations; terminating program with its frame is closed; Listing AWT threads; displaying Chinese character on frames; drawing graphics on frames.

Creating Frames with Sizes and Locations

Closing Frame and Terminating Application

Listing and Interrupting AWT Threads

"AWT blocker activation interrupted" Error

Displaying Chinese Characters in Frame Title

Drawing Graphics - Using paint() on Frame

Drawing Graphics - Using paint() on Component

Drawing Graphics - Using paint() on Content Pane

Drawing Chinese Characters on Frames

Conclusion:

  • JFrame.setVisible() starts AWT threads and displays the frame on the screen.
  • JFrame.setDefaultCloseOperation() can be used to terminate the program when its frames are closed.
  • JFrame.setContentPane() can be used to replace the content pane with your own components.
  • The best way to draw graphics on a frame is to draw graphics on its content pane component.
  • JComponent.setFont() can be use to set Chinese fonts and draw Chinese characters.

Dr. Herong Yang, updated in 2009
JFrame - Main Frame Class