RMI, and Java GUIs - PowerPoint PPT Presentation

About This Presentation
Title:

RMI, and Java GUIs

Description:

RMI, and Java GUIs 4-3-2002 Comments Everyone should be filling out and turning in group evaluations. These are largely for your protection. It can be used to point ... – PowerPoint PPT presentation

Number of Views:112
Avg rating:3.0/5.0
Slides: 15
Provided by: MarkL167
Learn more at: http://cs.trinity.edu
Category:
Tags: rmi | guis | java

less

Transcript and Presenter's Notes

Title: RMI, and Java GUIs


1
RMI, and Java GUIs
  • 4-3-2002

2
Comments
  • Everyone should be filling out and turning in
    group evaluations. These are largely for your
    protection. It can be used to point out where
    there are problems in group mechanics.
  • I had planned on talking about sequence diagrams
    today, but Im going to push that back a week and
    discuss some Java topics instead.

3
Remote Method Invocation
  • Java makes virtually all network communication
    easier than it is in C/C. This is particularly
    true when using RMI.
  • With RMI you can treat objects on other computers
    as if they were local on your own computer and
    call methods on them accordingly. Of course,
    there is a lag when you do this, but you dont
    have to explicitly worry about the socketing and
    whatnot.

4
Remote Interfaces
  • The entity you get for an object remotely is
    actually not the object itself, but an interface
    that object implements. The interface must
    extend java.rmi.Remote.
  • The implementation class should also extend
    java.rmi.server.UnicastRemoteObject.
  • Note that this implies that the implementation
    can have more functionality than the remote
    interface does.
  • All remote methods can throw java.rmi.RemoteExcept
    ion.

5
Passing
  • Different types of objects are passed differently
  • Remote objects - any object that extends
    java.rmi.Remote is passed as a remote object.
    You get a skeleton that does network
    communication.
  • Serializable objects - If an object is not Remote
    it must be serializable and then it is passed by
    value.
  • Primitives - No pass by reference of primitives

6
Registering and Lookup
  • Once you have a remote object, it can pass you
    others, but getting the first one takes a
    different approach.
  • An object can register itself with the rmi
    registry using the rebind method of
    java.rmi.Naming. (You have to start a local
    registry with rmiregistry first.)
  • Objects can get a remote reference to a
    registered object using the lookup method of
    java.rmi.Naming.

7
Compiling
  • Once you have written your code you first compile
    it with a normal Java compiler. After that you
    have to do another step to create stub and
    skeleton classes that do most of the work behind
    RMI. You to this is the RMI compiler, rmic.
    Just run rmic specifying the name of the
    implementation class.

8
Java GUIs
  • One of the greatest things about Java, from an
    application building standpoint, is how easy it
    is to make a GUI in it.
  • Since 5 out of 8 of the groups HAVE to do this to
    implement anything we will take a few minutes to
    discuss it.
  • Java has two graphics libraries, AWT and Swing.
    They work very similarly.

9
AWT
  • The AWT library uses inheritance extensively.
    Components of the GUI are represented by the
    component class. Container is a subclass of
    Component that can have other components added to
    it. Each of these has other subclasses
    representing buttons, windows, text fields,
    labels, etc.

10
Layouts
  • To make Java GUIs portable, they use layout
    managers to position and size various components.
    You can place things at specific locations on
    the screen, but that isnt very portable.
  • Every container has a layout manager it uses to
    place the components in it. By nesting
    containers and layout managers you can get great
    flexibility.

11
Some Layout Managers
  • Here are some of the layout managers in AWT.
  • FlowLayout - places one component after another
    like text on a page.
  • GridLayout - places components on a regular grid.
  • BorderLayout - Objects can be placed a north,
    south, east, west, or center.
  • GridBagLayout - A powerful layout manager for
    placing objects in an irregular grid.

12
Events
  • No GUI is complete unless it can react to the
    user. User interactions with a GUI are called
    events and we want to be able to create code to
    handle events.
  • In Java (since version 1.1) we do this be
    attaching event listeners to GUI components.
    When an event happens for an object all the
    appropriate listeners for that object are called.

13
Events and Listeners
  • There are a fair number of event types and
    listeners.
  • The listeners include ActionListener,
    MouseListener, KeyListener, and FocusListener.
    Each listener type has certain methods that it
    must define.
  • Action events are some of the most common and
    happen when you do things like click buttons.

14
Swing
  • Swing is actually based on AWT, but provides a
    look and feel that is machine independent. It
    has pretty much all the same objects but the
    names typically start is J (i.e. JButton and
    JFrame).
  • Swing also has other classes AWT didnt. These
    include JTable, JTree, JColorChooser, and
    JToolBar.
  • AWT or Swing for project?
Write a Comment
User Comments (0)
About PowerShow.com