lec8 - COMP201 Java Programming Part II: GUI Programming...

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

View Full Document Right Arrow Icon
COMP201 Java Programming Part II: GUI Programming Topic 8: Basics of Graphics Programming Reading: Chapter 7
Background image of page 1

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

View Full DocumentRight Arrow Icon
COMP201 Topic 8 / Slide 2 Outline Introduction: Ingredients of Swing GUI Creating a frame (window) Displaying information in a panel Displaying texts 2D shapes Colors and fonts Images
Background image of page 2
COMP201 Topic 8 / Slide 3 Introduction: Ingredients of Swing GUI Top-level container: JFrame (Window) in this case Menu bar (optional) contentPane : contains all visible components Intermediate containers to organize various GUI components: JPanel s in this case JPanel3 JPanel1 JPanel2 Build GUI with javax.Swing, JDK1.2 Better than java.awt, JDK1.1
Background image of page 3

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

View Full DocumentRight Arrow Icon
COMP201 Topic 8 / Slide 4 To create a swing GUI 1. Create a top-level container: JFrame 1. Get contentPane of the top-level container 1. Create JPanel s and add GUI components to the JPanel s 1. Layout the JPanel s onto the contentPane . JPanel s can contain Atomic components such as JButton s and Jlabel s (Topic 10) Custom graphics such as text, shapes, and images (This Topic) Introduction: Ingredients of Swing GUI
Background image of page 4
COMP201 Topic 8 / Slide 5 Creating a Frame Frame: top-level window, not contained inside another window. Use JFrame class in javax.swing package. What can you do with JFrame : - Create a new one - get/setSize - get/setLocation - get/setTitle - show/hide - toFront/toBack - is/setResizable - dispose - setIconImage
Background image of page 5

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

View Full DocumentRight Arrow Icon
COMP201 Topic 8 / Slide 6 Creating a Frame Most methods for working with JFrame inherited from superclasses: Object JFrame Component Container Window Frame JPanel JComponent Ancestor of all GUI objects
Background image of page 6
COMP201 Topic 8 / Slide 7 Creating a Frame java.awt.Component: getLocation, setBounds, setLocation, getSize, setSize, setBackground, setForeground, repaint, …… java.awt.Window: toFront, toBack, show, hide, …… java.awt.Frame: dispose, setResizable, setTitle, setIcomImage, ……
Background image of page 7

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

View Full DocumentRight Arrow Icon
COMP201 Topic 8 / Slide 8 Creating a Frame Example: class SimpleFrame extends JFrame { public SimpleFrame() { setSize (WIDTH, HEIGHT); } public static final int WIDTH = 300; public static final int HEIGHT = 200; } Default constructor of JFrame is called. Default size of a JFrame : 0x0
Background image of page 8
COMP201 Topic 8 / Slide 9 Creating a Frame Things to know about coordinates Units are expressed pixels (depends on resolution) Coordinate system is vertically-flipped from Cartesian (0,0) is upper left corner of screen Frame defaults to location (0,0) and size (0,0)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Creating a Frame import javax.swing.*; public class SimpleFrameTest { public static void main( String [] args) { SimpleFrame frame = new SimpleFrame (); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.show(); } } // SimpleFrameTest.java Create a SimpleFrame. Show it.
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 36

lec8 - COMP201 Java Programming Part II: GUI Programming...

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

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