Cross-platform programming

Download Report

Transcript Cross-platform programming

Cross-Platform Programming
Making everyone happy
CS 102-02
Lecture 6-2
May 6, 1998
CS102-02
Lecture 6-2
Agenda
• Two kinds of inheritance
• Interfaces in Java
• The End of OO
May 6, 1998
CS102-02
Lecture 6-2
Web vs. Java Design
• Web designers are used to testing their
sites and pages on
– Multiple platforms
– Screen resolutions
– Color ranges
– Browsers
• Can't just create Web sites on and for
their own high-powered, million-color
development machines
May 6, 1998
CS102-02
Lecture 6-2
Graphics across Platforms
• Different computers almost agree on
text, but strongly disagree on graphics
– Screen resolutions
– Colors: 8-bit grey, 16-bit and 24-bit
– Fonts: Not everybody has Times New
Roman Narrow
– User interface: Keyboards, mouse button
count and accessibility
May 6, 1998
CS102-02
Lecture 6-2
Cross-Platform Fonts
• Different platforms have different fonts
– Different names for similar fonts
• Java has a set of logical fonts
– Monospaced, Dialog, Serif and Sans Serif
– Font attributes (size, style, ...)
May 6, 1998
CS102-02
Lecture 6-2
The Abstract Windowing Toolkit
• Abstract away the details of building
graphical user interfaces (GUIs)
May 6, 1998
CS102-02
Lecture 6-2
The AWT Hierarchy
May 6, 1998
CS102-02
Lecture 6-2
The Need for Abstraction
May 6, 1998
CS102-02
Lecture 6-2
Arranging Things
• Java uses layout managers to control
how components appear on-screen
– Achieve different effects by using different
layout managers
– Going without
Grid layout
May 6, 1998
Flow layout
CS102-02
Lecture 6-2
Laying It All Out
May 6, 1998
CS102-02
Lecture 6-2
Picking a Layout Manager I
• Need to display a component in as
much space as it can get.
– Consider using BorderLayout
• put the space-hungry component in the center
– GridBagLayout
• Set the constraints for the component so that
fill=GridBagConstraints.BOTH
From The Java Tutorial
May 6, 1998
CS102-02
Lecture 6-2
Picking a Layout Manager II
• Need to display a few components in a
compact row at their natural size.
– Use a Panel to hold the components
– Use Panel's default FlowLayout manager
• Need to display a few same-sized
components in rows and/or columns.
– GridLayout fits the bill
From The Java Tutorial
May 6, 1998
CS102-02
Lecture 6-2
The AWT Works for You
• Abstraction is all well and good, but
Java programs still need to run on
actual machines
• Just one API for buttons (provided by
the Button class)
– Looks different on a Macintosh than on a
PC running Windows 95.
• Peer classes link the AWT components
you see to the underlying platform
May 6, 1998
CS102-02
Lecture 6-2
Behind the Scenes
May 6, 1998
CS102-02
Lecture 6-2
Swingin' with Java
• Swing components are lightweight
• Use a different architecture than AWT
May 6, 1998
CS102-02
Lecture 6-2
Swing Look-and-Feel
Metal
(Java)
Early Mac
Motif
Windows
Organic
(Santa Fe)
Organic
(Vancouver)
May 6, 1998
CS102-02
Lecture 6-2
Beans
• JavaBeans is a portable, platformindependent software component model
• written in Java
• Enables developers to write reusable
components once and run them
anywhere
May 6, 1998
CS102-02
Lecture 6-2
Going Cross-Platform with Java
• Graphics
– GUI components
– Fonts
– Swing
• Sharing software
– Beans
May 6, 1998
CS102-02
Lecture 6-2