To display other GUI components on a JFrame, we first need to get the content pane of the JFrame and then add the desired GUI components to this content pane.
If we want to arrange the added GUI components in certain ways, we need to add an appropriate "layout manager" to the JFrame. The task of laying out the GUI component inside of a container GUI component is specifed by an interface called LayoutManager. In Frame1, we add the FlowLayout that arranges all GUI components in a linear fashion. If we do not add any layout manager to the JFrame, it has no layout manager and does a very bad job of arranging GUI components inside of it. As an exercise, comment out the code to add the FlowLayout to Frame1 and see what happens!
- 瀏覽次數:1446