Java Foundation Classes - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Java Foundation Classes

Description:

caused cross platform problems (inconsistent behavior) ... Screen Magnifier -- adjust magnification from 1 to 16 times, text smoothing and ... – PowerPoint PPT presentation

Number of Views:251
Avg rating:3.0/5.0
Slides: 25
Provided by: joseph120
Category:

less

Transcript and Presenter's Notes

Title: Java Foundation Classes


1
Java Foundation Classes
  • Joe Komar

2
Java Foundation Classes (JFC)
  • GUI classes
  • Extends original AWT
  • Completely portable
  • Delivered with base JDK
  • Performance improvements
  • Provide selectable look and feel
  • Written as JavaBeans

3
Abstract Windows Toolkit (AWT)
  • Each Java component creates a native component
  • layered toolkit approach
  • peer model
  • caused cross platform problems (inconsistent
    behavior)
  • restrictive in rendering and event handling
  • difficult to override or extend aspects of the
    component

4
The Players...
  • Internet Foundation Classes -- Netscape
  • One standard (JFC) developed by
  • Sun
  • Netscape
  • IBM

5
JFC Features
  • Swing components
  • Pluggable Look and Feel
  • Accessibility Features
  • 2D API
  • Drag and Drop

6
Swing Components
  • Lightweight - can be overlaid one on another
  • No more native code used
  • Include new versions of Button, Scrollbar,
    TextField, Combo box, Checkbox, List, Menu,
    MenuBar, ScrollPane
  • Include new components such as ProgressBar,
    PainSplitter, MessageBox, Styled Text, etc.

7
Swing Components -- Delegation Event Model
  • Complex if..then..else code was needed to
    determine what triggered an evet
  • Same event handling model as JavaBeans
  • Listeners register with the object (event source)
  • When an event occurs, the Listeners are notified

8
Swing Components -- Printing
  • Used to have to use native code for printing text
    and graphics
  • Uses
  • java.awt.PrintGraphics interface to get a
    Graphics context
  • call to getPrintJob in the java.awt.PrintJob
    class to get a print dialogue box

9
Printing
PrintJob pjob getToolkit().getPrin
tJob( this,"Tester",null)
Graphics pg pjob.getGraphics()
printAll(pg)
pg.dispose() pjob.end()
10
Using Swing Components
  • Locate and complete the tutorial on Swing
    provided by Sun (http//java.sun.com/docs/books/tu
    torial/ui/swing/index.html)
  • Differences between using in an Application and
    using in an Applet
  • Application -- basically use as any other
    component -- drag, drop, add interaction
  • Applet -- need to make some modifications to
    Visual Cafés generated code (see next slides)
    and use Panels

11
Swing4
import java.awt. import java.applet. import
com.sun.java.swing.JButton import
com.sun.java.swing.JTextField import
com.sun.java.swing.JPanel import
com.sun.java.swing.JApplet
12
Swing4
public class Swing4 extends JApplet
_

_ public void init()
_

_ // Take out
this line if you don't use symantec.itools.net.Rel
_ symantec.itools.lang.Context.set
Applet(this) _

_ // This code is
automatically generated by Visual Cafe when yo_
// components to the visual
environment. It instantiates and i_
// the components. To modify the code, only use
code syntax th_ // what Visual
Cafe can generate, or Visual Cafe may be unable_
// parse your Java file into its
visual environment. _
//INIT_CONTROLS
_
13
Swing4
getContentPane().setLayout(null) setSize(472,338)
jPanel1 new com.sun.java.swing.JPanel() jPane
l1.setLayout(null) jPanel1.setBounds(12,24,425,27
3) jPanel1.setFont(new Font("Dialog",
Font.PLAIN, 12)) jPanel1.setForeground(new
Color(0)) jPanel1.setBackground(new
Color(-3355444)) getContentPane().add(jPanel1)
14
Swing4
jTextField1 new com.sun.java.swing.JTextField()
jTextField1.setMargin(new java.awt.Insets(0,0,0,0
)) jTextField1.setBounds(132,96,168,24) jTextFie
ld1.setFont(new Font("SansSerif", Font.PLAIN,
12)) jTextField1.setForeground(new
Color(0)) jTextField1.setBackground(new
Color(16777215)) jPanel1.add(jTextField1) jButto
n1 new com.sun.java.swing.JButton() jButton1.se
tBounds(180,144,72,24) jButton1.setFont(new
Font("Dialog", Font.BOLD, 12)) jButton1.setForegr
ound(new Color(0)) jButton1.setBackground(new
Color(-3355444)) jPanel1.add(jButton1) //
15
Swing4
//REGISTER_LISTENERS SymAction
lSymAction new SymAction()
jButton1.addActionListener(lSymAction)
// //DECLARE_CONTROLS
com.sun.java.swing.JPanel jPanel1
com.sun.java.swing.JTextField jTextField1
com.sun.java.swing.JButton jButton1 //
16
Swing4
class SymAction implements java.awt.event.ActionLi
stener public void actionPerformed(java.
awt.event.ActionEvent event)
Object object event.getSource()
if (object jButton1)
jButton1_actionPerformed(event)
17
Swing4
void jButton1_actionPerformed(java.awt.event.Acti
onEvent event) // to
do code goes here.
//CONNECTION // setText...

jTextField1.setText("Button Pushed")
//
//CONNECTION // Set the
Background Color... The color blue
jTextField1.setBackgrou
nd(Color.blue)
//
18
Swing4 Output
19
Pluggable Look and Feel (LAF)
  • Can specify LAF for Windows, Motif, MacOs, and
    Metal (Java LAF)
  • Primarily for Network Computers
  • Can switch from one LAF to another without
    reloading the application
  • Can run a motif LAF on a Windows system
  • Determined and specified when JAR files are built

20
Accessibility Features
  • Screen Reader -- creates and off screen
    representation of the GUI component -- e.g.,
    text, Braille, speech
  • Screen Magnifier -- adjust magnification from 1
    to 16 times, text smoothing and highlighting,
    event tracking, etc.

21
2D API(JDK 1.2)
  • Extends the java.awt.image library
  • Subclass of the AWT Graphics class, Graphics2D
  • Text treated as graphics
  • Mixed fonts, mixed languages, bidirectional text
  • Control of rendering of images -- e.g. stroke
    width, joint types, color and texture fills, etc.

22
Drag and Drop(JDK 1.2)
  • Drag and drop between Java applications and other
    applications
  • Generic and platform-independent -- same code for
    Unix to Motif as for Java on Windows

23
Other JFC Features
  • Data Transfer/Clipboard -- transferable objects
    with data flavors
  • Desktop Colors -- java.awt.SystemColor
  • Graphics and Image Enhancements -- clipping area,
    new drawImage methods for scaling and flipping,
    MemoryImageSource class, ColorModel
  • Mouseless Operation -- MenuShortcut class
  • Popup Menu -- PopupMenu component
  • ScrollPane Container -- new class

24
JFC and Swing Assignment
  • Use Visual Café and produce an Application
  • Use at least four different Swing components
  • Make them interact in some way
  • Add some custom interaction to the methods
    generated through Visual Café
  • Add the ability to print the frame
  • Turn in one week from today
Write a Comment
User Comments (0)
About PowerShow.com