Learning Java: Day 13

Working With Swing Components

Component is the more correct term for what I've been referring to as widgets. Those are the things you put in a GUI, or the things that the user sees and interacts with. Almost every thing you can stick in a GUI extends from javax.swing.JComponent.

Chapter 13 of Head First Java covers the layout managers for JPanel and JFrame, creating scrollbars on textboxes, making lists, and finally, creating the BeatBox midi player.

Fact 1: Different layout managers have different policies and you have to memorize what they are if you want your buttons/textboxes/lists/etc to be placed where you actually want them to be.

Fact 2: BorderLayout is the default layout manager for a frame; FlowLayout is the default for a panel.

Fact 3: When you add a component to another component, the added component is controlled by the layout manager of the background component.

Three layout managers: border, flow, and box.
BorderLayout: the BorderLayout manager divides a background component into five regions (NORTH, SOUTH, EAST, WEST, CENTER). You can only add one component per region to a background controlled by a BorderLayoutManager. This is the default layout manager for a frame.

FlowLayout: the FlowLayout manager lays out components from left to right, top to bottom, in the order they were added, wrapping to a new line when needed. This is the default layout manager for a panel.

BoxLayout: the BoxLayout manager places components from top to bottom, one per line.

Most of my time spent in this chapter was typing the code for the BeatBox and then debugging it prior to compiling. Debugging might be the most useful skill I'll learn as I work my way through the book.

School is starting on September 8th.  I still have 5 more chapters and 2 appendices to work through before school begins.  I've gotta work faster!

0 comments:

Post a Comment