lecture15 - Introduction to Computation and Problem Solving...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Introduction to Computation and Problem Solving Prof. Steven R. Lerman and Dr. V. Judson Harward Class 15: Class 15: Constructing Interfaces with Constructing Interfaces with Swing Swing 2 Topics In this lecture, we are going to explore how to build more complex interfaces with Swing. We will not demonstrate many components; for that see http://java.sun.com/docs/books/tutorial/uiswing/components/components.html We will explore how to build up an interface component by component and container by container; how to use layout management to configure your GUI Tuesday's active learning will focus on how to make your program respond to events. 1
Image of page 1

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

View Full Document Right Arrow Icon
3 Constructing GUIs simple calculator. the containers into larger containers. JPanel interfaces. It is ) Later in this course, we are going to build a We will build the GUI by nesting simpler components into containers, and then combining is the workhorse of most complicated a good all purpose container the standard drawing surface (Lecture 17 a base class for many composite components 4 1. Overall subclass of 2.1 2.2 2.2.1 subclass Calculator GUI JFrame 2. Reusable JPanel JPanel contains JLabel JPanel subclass Keypad JButton KeyButton 2
Image of page 2
5 Calculator GUI Diagram 1. 2. 1. 2.1 2.1.1 2.2 2.2.1 JFrame Calculator extends JPanel JFrame. contentPane JPanel the result pane JLabel Keypad extends JPanel KeyButton extends JButton 6 Layout management is the process of components. an instance of another class. different layout policy . Container content = getContentPane(); content.setLayout( new FlowLayout() ); Layout Management, 1 determining the size and location of a container's Java containers do not handle their own layout. They delegate that task to their layout manager, Each type (class) of layout manager enforces a If you do not like a container's default layout manager, you can change it. 3
Image of page 3

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

View Full Document Right Arrow Icon
7 If a container encloses another container, the enclosing container can not position the inner container nor size itself until it knows how big the inner container needs to be. And the inner container can not size itself Layout Management, 2 Layout management proceeds top down in the containment hierarchy. until it queries its contents. 8 1. Overall subclass of 2.1 2.2 2.2.1 subclass Calculator GUI JFrame 2. Reusable JPanel JPanel contains JLabel JPanel subclass Keypad JButton KeyButton 4
Image of page 4
9 Calculator GUI Diagram 1. 2. 1. 2.1 2.1.1 2.2 2.2.1 depends on depends on depends on both depends on 20 of depends on JFrame Calculator extends JPanel JFrame. contentPane JPanel JLabel Keypad extends JPanel KeyButton extends JButton 10 good reason. via a call to setLayout(null) . calls to setSize() setLocation() single call to setBounds() . Turning off Layout Management Although layout managers can introduce additional complexity, they are there for a very The effect of layout management can be turned off by eliminating a container's layout manager The user must then explicitly lay out each component in absolute pixel coordinates through and or a The problem with this strategy is that it lacks flexibility.
Image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern