ch14 - Chapter 14 MORE SWING OBJECTS 14.1 MENUS 115...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
113 Chapter 14 M ORE S WING O BJECTS M S O 14.1 M ENUS 115 Programming Example A GUI with a Menu 115 Menu Bars, Menus, and Menu Items 115 Nested Menus 120 14.2 M AKING GUI S P RETTY ( AND M ORE F UNCTIONAL ) 122 Adding Icons 122 Gotcha Resizing Buttons 125 The JScrollPane Class for Scroll Bars 130 Adding Borders 135 Gotcha Forgetting to Import javax.swing.border 140 Changing the Look and Feel 141 Lightweight and Heavyweight Components (Optional) 144 14.3 M ORE L AYOUT M ANAGERS 147 The BoxLayout Manager Class 148 Struts and Glue 152 Gotcha Using Struts and Glue with Other Layout Managers 153 The Box Container Class 154 The CardLayout Manager 157 14.4 I NNER C LASSES 162 Helping Classes 163 14.5 M ORE ON E VENTS AND L ISTENERS 163 The WindowListener Interface 165 Programming the Close-Window Button 169 Programming Example Components with Changing Visibility 174 Some More Details on Updating a GUI 178 14.6 A NOTHER L OOK AT THE S WING C LASS H IERARCHY 178 Buttons, Menus, and Abstract Buttons 179 Programming Tip More Methods for the Class JMenuItem 179 Programming Tip There are a Lot More Swing Classes and Methods 180 Chapter Summary 181 Answers to Self-Test Questions 182 Programming Exercises 186
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
M ORE S WING O BJECTS M S O The more the merrier. J OHN H EYWOOD , Proverbs ( 1546) In this chapter we give you some additional information about Swing, so that you can create more profession looking GUIs. Section 14.1 introduces menus, which we have not discussed before. However, as you will see, much of what you learned about buttons will carry over to menus. So, Swing menus will not look completely new to you. The material in Sections 14.2 through 14.1 cover some enhancements of basic things you already are doing with Swing. In particular, Section 14.1 covers inner classes. Section 14.2 covers look and feel in Swing, a topic that is something of a hall- mark for Swing. Along the way you will learn about these Swing (or Swing-related) classes: AbstractButton , Box BoxLayout BevelBorder Dimension EmptyBorder , EtchedBorder ImageIcon Inset JMenu JMenuBar JMenuItem JScrollPane , LineBorder MatteBorder , and others. Objectives Learn to add menus, icons, borders, and scroll bars to your GUIs. Understand the BoxLayout manager and the Box class. Find out how to change the look and feel of a Swing GUI. Understand some uses and advantages of inner classes. Learn about the WindowListener interface. Find out how to create GUIs with components that change from visible to invisible and vice versa. Prerequisites Before covering this chapter, you need to have covered Chapter 12 which introduces you to Swing. You do not need to have covered Chapter 13 (Applets) before cover- ing this chapter. For the subsection entitled Changing the Look and Feel in Section 14.2, you need to have read the beginning of Chapter 8 on exception handling. The boxed subsection Adding Icons to Menu Items (Alternative Ordering) in Section 14.1 naturally requires that you ±rst cover the subsection Menu Bars, Menus, and Menu Items in Section 14.2. Aside from that one clearly marked boxed subsection, the sections 14.2 (menus), 14.2 (icons, look and feel, plus other good-
Background image of page 2
14.1 Menus 115 ies), 14.3 (
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 74

ch14 - Chapter 14 MORE SWING OBJECTS 14.1 MENUS 115...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online