课程: Learning Java Swing

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Frames and panels

Frames and panels

- [Instructor] Since we're working with Swing, it's important to understand in a little bit more detail how frames and panels work together. Once a frame is instantiated, we can add one or more panels to that frame. When we instantiate a frame, it has two primary instructors, an empty constructor and a constructor that accepts a string for the title of the frame. The title appears in the top bar of the frame. In this example, we have one panel on our frame called contentPanel. Notice that the contentPanel has a layout of GridLayoutManager. This type of layout uses rows and columns to organize the components. Do you see these green bars at the top and on the left? They represent the rows and columns, which default to one row and one column. Let's switch over to the code for this UI. You can see I've already added some code here. I have the TicTacToeUI extends JFrame. Then we have our contentPanel, which was added by the GUI editor. Then we have the default instructor, which allows us…

内容