nov 061 size control how is a component’s size determined during layout and during resize...
TRANSCRIPT
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
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)
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
Nov 06 4
BorderLayout
Flow Layout
GridLayout
BoxLayout
Expands to maximum size when resizing
OutputOutput
Nov 06 5
Default Layout Default Layout ManagersManagers
JPanel = FlowLayoutJFrame’s content pane = BorderLayout
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
Output ModelOutput Model
A picture is worth a thousand words
Nov 06 8
Coordinate SystemsCoordinate Systems
Device coordinatesPhysical coordinates
Nov 06 9
Device CoordinatesDevice Coordinates
Most natural units for the output deviceTypically dots or pixelsOrigin possibilities
CentreBottom leftUpper left
Nov 06 10
Physical CoordinatesPhysical Coordinates
Printed page inches, cm
Architectural drawingsfeet, meters
Nov 06 11
Component
Java’s Coordinate Java’s Coordinate SystemSystem
(0,0)
x
y (width – 1, height - 1)
Nov 06 12
Example Program Example Program (shown earlier)(shown earlier)DemoMouseEvents.java
(x, y)coordinate of pointer incomponent
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)
Nov 06 14
An image presented on a An image presented on a display is composed of display is composed of
pixelspixels
pixel
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”
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)
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
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
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
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
Nov 06 21
Dot Pitch IllustratedDot Pitch Illustrated
Pixel
0.481 mm
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:
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
Nov 06 24
RGB modelRGB model
blackblue red
greencyancyan yellowyellow
white
magenta
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
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
Nov 06 27
Java’s Java’s JColorChooserJColorChooser (1) (1)
Pre-definedpallete
For a demo, seeDemoMenu2.java
Nov 06 28
Java’s Java’s JColorChooserJColorChooser (2) (2)
HSB For a demo, seeDemoMenu2.java
Nov 06 29
Java’s Java’s JColorChooserJColorChooser (3) (3)
RGB For a demo, seeDemoMenu2.java
Nov 06 30
Microsoft OfficeMicrosoft Office
Nov 06 31
Netscape Navigator and Netscape Navigator and Microsoft IEMicrosoft IE
Nov 06 32
Paint Shop ProPaint Shop Pro
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
Nov 06 34
Example ProgramExample Program
DemoPaintPanel.java
Nov 06 35
Example ProgramExample ProgramDemoPaintPanel2.javaDemoPaintPanel3.java
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