size control

36
Nov 06 1 Size Control Size Control How is a component’s size determined during layout and during resize operations? Three factors determine component sizes: The component’s size properties (preferred, minimum, and maximum) Whether the size properties are “assumed” or “explicitly set” Layout manager policies

Upload: langer

Post on 05-Jan-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Size Control. How is a component’s size determined during layout and during resize operations? Three factors determine component sizes: The component’s size properties (preferred, minimum, and maximum) Whether the size properties are “assumed” or “explicitly set” Layout manager policies. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Size Control

Nov 06 1

Size ControlSize Control

How is a component’s size determined during layout and during resize operations?Three factors determine component sizes:

The component’s size properties (preferred, minimum, and maximum)Whether the size properties are “assumed” or “explicitly set”Layout manager policies

Page 2: Size Control

Nov 06 2

Example ProgramExample Program

DemoSizeControl.java

usage: java DemoSizeControl arg1

where 'arg1' specifies the layout manager as follows: 1 = BorderLayout 2 = FlowLayout 3 = GridLayout 4 = BoxLayout

Example (next 2 slides)

Page 3: Size Control

Nov 06 3

Example Program (2)Example Program (2)

JButton b1 = new JButton("Button One");JButton b2 = new JButton("B2");JButton b3 = new JButton("B3");JButton b4 = new JButton("B4");

b3.setMaximumSize(b1.getPreferredSize());

b4.setPreferredSize(new Dimension(150, 50));b4.setMaximumSize(new Dimension(150, 50));

Component construction and configuration

Page 4: Size Control

Nov 06 4

BorderLayout

Flow Layout

GridLayout

BoxLayout

Expands to maximum size when resizing

OutputOutput

Page 5: Size Control

Nov 06 5

Default Layout Default Layout ManagersManagers

JPanel = FlowLayoutJFrame’s content pane = BorderLayout

Page 6: Size Control

Nov 06 6

Programming Programming ChallengeChallenge

Create a GUI layout, as follows

Clear Exit

Enter some text:

Clear Exit

Enter some text:

Upon launching After resizing

Page 7: Size Control

Output ModelOutput Model

A picture is worth a thousand words

Page 8: Size Control

Nov 06 8

Coordinate SystemsCoordinate Systems

Device coordinatesPhysical coordinates

Page 9: Size Control

Nov 06 9

Device CoordinatesDevice Coordinates

Most natural units for the output deviceTypically dots or pixelsOrigin possibilities

CentreBottom leftUpper left

Page 10: Size Control

Nov 06 10

Physical CoordinatesPhysical Coordinates

Printed page inches, cm

Architectural drawingsfeet, meters

Page 11: Size Control

Nov 06 11

Component

Java’s Coordinate Java’s Coordinate SystemSystem

(0,0)

x

y (width – 1, height - 1)

Page 12: Size Control

Nov 06 12

Example Program Example Program (shown earlier)(shown earlier)DemoMouseEvents.java

(x, y)coordinate of pointer incomponent

Page 13: Size Control

Nov 06 13

PixelsPixels

A Pixel is a “picture element”a single point in a graphic imageA graphics display is divided into thousands (or millions) of pixels arranged in rows and columnsThe pixels are so close together they appear connectedThe number of bits used to represent each pixel determines how many colours or shades of grey can be representedFor a B&W (black and white) display, each pixel is represented by 1 bitWith 8 bits per pixel, a monitor can display 256 shades or grey or 256 colours (Note: 28 = 256)

Page 14: Size Control

Nov 06 14

An image presented on a An image presented on a display is composed of display is composed of

pixelspixels

pixel

Page 15: Size Control

Nov 06 15

Display SizeDisplay Size

Usually specified in “inches”Value cited is the diagonal dimension of the raster -- the viewable area of the displayE.g., a 15” monitor

15”

Page 16: Size Control

Nov 06 16

ResolutionResolution

Resolution is the number of pixels on a displayUsually cited as n by m

n is the number of pixels across the displaym is the number of pixels down the display

Typical resolutions range from…640 by 480 (low end), to1,600 by 1,200 (high end)

Page 17: Size Control

Nov 06 17

Video RAM Video RAM RequirementsRequirements

Total number of pixels is n mExamples

640 480 = 307,200 pixels1,600 1,200 = 1,920,000 pixels

Video RAM required equals total number of pixels times the number of bits/pixelExamples

640 480 8 = 2,457,600 bits = 307,200 bytes = 300 KB 1,600 1,200 24 = 46,080,000 bits = 5,760,000 bytes = 5,625 KB = 5.49 MBNote: 1 KB = 210 = 1024 bytes, 1 MB = 220 = 1,048,576 bytes

Page 18: Size Control

Nov 06 18

Resolution

Bits per pixel

8 bit 16 bit 24 bit

640 x 480 300 600 900

800 x 600 468.75 937.5 1406.25

1024 x 768 768 1536 2304

1152 x 1024 1152 2304 3456

1280 x 1024 1280 2560 3840

1600 x 1200 1875 3750 5625

Video RAM (KB) By Video RAM (KB) By ResolutionResolution

Page 19: Size Control

Nov 06 19

Aspect RatioAspect Ratio

Aspect ratio is the ratio of the width to height of a display screenFor a 640 by 480 display, the aspect ratio is 640:480, or 4:3Related terms

LandscapeThe width is greater than the height

PortraitThe height is greater than the width

Page 20: Size Control

Nov 06 20

Dot PitchDot Pitch

Dot pitch is a measure of the diagonal distance between pixels on a display screenOne of the principal characteristics that determines the quality of a displayThe lower the number, the crisper the imageCited in mm (millimeters)Typical values range from 0.15 mm to 0.30 mmDot pitch, as specified, is the capability of the display

Page 21: Size Control

Nov 06 21

Dot Pitch IllustratedDot Pitch Illustrated

Pixel

0.481 mm

Page 22: Size Control

Nov 06 22

Dot Pitch Image Dot Pitch Image ExampleExample

Q: What is the dot pitch of an image displayed on a 15” monitor with a resolution of 640 by 480?A:

640

480Z1. Z = (6402 + 4802)1/2 = 800

2. 1 mm = 0.039 inch

Dot pitch = 15 / 800 inches= 0.01875 inches= 0.01875 / 0.039 mm= 0.481 mm

Notes:

Page 23: Size Control

Nov 06 23

Two models for colourTwo models for colour

RGB Individual specifications for RED, GREEN, and BLUE

HSBIndividual specifications for hue, saturation, and brightnessTogether, hue and saturation are called chrominance; they represent the colourHue is the distinction between colours (e.g., red, orange, yellow, green, etc.)Saturation is the purity of a colour, or the amount of grey in proportion to the hue

High saturation very intenseLow saturation washed outZero saturation white

brightness is also called luminance or intensity

Page 24: Size Control

Nov 06 24

RGB modelRGB model

blackblue red

greencyancyan yellowyellow

white

magenta

Page 25: Size Control

Nov 06 25

RGB Model (2)RGB Model (2)

Color Red Green BlueRed 255 0 0Green 0 255 0Blue 0 0 255Yellow 255 255 0Cyan 0 255 255Magenta 255 0 255White 255 255 255Black 0 0 0

Page 26: Size Control

Nov 06 26

Colour ChoosersColour Choosers

Control for colour usually employs a colour chooser (aka colour picker)Colour selected three ways:

A pre-defined palette HSB values RGB values

Page 27: Size Control

Nov 06 27

Java’s Java’s JColorChooserJColorChooser (1) (1)

Pre-definedpallete

For a demo, seeDemoMenu2.java

Page 28: Size Control

Nov 06 28

Java’s Java’s JColorChooserJColorChooser (2) (2)

HSB For a demo, seeDemoMenu2.java

Page 29: Size Control

Nov 06 29

Java’s Java’s JColorChooserJColorChooser (3) (3)

RGB For a demo, seeDemoMenu2.java

Page 30: Size Control

Nov 06 30

Microsoft OfficeMicrosoft Office

Page 31: Size Control

Nov 06 31

Netscape Navigator and Netscape Navigator and Microsoft IEMicrosoft IE

Page 32: Size Control

Nov 06 32

Paint Shop ProPaint Shop Pro

Page 33: Size Control

Nov 06 33

DrawingDrawing

Java’s “J” components are the building blocks of graphical user interfacesAt a lower level, Java provides a set of drawing primitives for

ShapesLinesCurves ImagesText

Page 34: Size Control

Nov 06 34

Example ProgramExample Program

DemoPaintPanel.java

Page 35: Size Control

Nov 06 35

Example ProgramExample ProgramDemoPaintPanel2.javaDemoPaintPanel3.java

Page 36: Size Control

Nov 06 36

Custom painting with Custom painting with SwingSwingJComponentJComponent

paintpaint

paintChildrenpaintChildrenpaintBorderpaintBorder

paintComponentpaintComponent

JPanelJPanelpaintpaint

paintChildrenpaintChildrenpaintBorderpaintBorder

paintComponentpaintComponent

PaintPanelPaintPanelpaintpaint

paintChildrenpaintChildrenpaintBorderpaintBorder

paintComponentpaintComponent

extends

extends

Never call paint()directly. Instead, call repaint()

The right methodto override forcustom painting