Se204 object oriented development
Download
1 / 34

SE204 Object-Oriented Development Jacqueline McQuillan B.Sc. - PowerPoint PPT Presentation


  • 447 Views
  • Uploaded on

SE204 Object-Oriented Development Jacqueline McQuillan B.Sc. NUI Maynooth Overview Java Graphics Threads I/O in Java Object Serialization Remote Method Invocation (RMI) More … Java Graphics Basic Java Graphics

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'SE204 Object-Oriented Development Jacqueline McQuillan B.Sc.' - paul


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Se204 object oriented development l.jpg

SE204 Object-Oriented Development

Jacqueline McQuillan B.Sc.

NUI Maynooth


Overview l.jpg
Overview

  • Java Graphics

  • Threads

  • I/O in Java

  • Object Serialization

  • Remote Method Invocation (RMI)

  • More …

2004/5: SE204: Lecture 1&2



Basic java graphics l.jpg
Basic Java Graphics

  • We can use Java to develop computer graphics based applications, both for 2-dimensional drawing and for Graphical User Interfaces(GUIs).

  • We will begin by looking at GUI programming in Java

2004/5: SE204: Lecture 1&2


A simple example l.jpg
A Simple Example

2004/5: SE204: Lecture 1&2


Another example l.jpg
Another Example

2004/5: SE204: Lecture 1&2


Graphical user interface l.jpg
Graphical User Interface

  • Use components to build our GUI

  • It is possible for a component to have a peer

  • The peer is a native implementation of that component

    • for instance, a button object in an application will correspond to the native button implemented by the operating system

2004/5: SE204: Lecture 1&2


Awt the abstract windows toolkit l.jpg
AWTThe Abstract Windows Toolkit

  • java.awt

  • components are heavyweight

    • appearance of awt component is determined by the peer component

    • look is platform dependent

2004/5: SE204: Lecture 1&2


Swing l.jpg
Swing

  • javax.swing

  • most of its components are lightweight

    • component has no peer

    • look is determined by the java runtime environment, so will look the same regardless of the platform being used

  • it is possible to make the swing components look like anything you want. This is referred to as pluggable look and feel(PLAF)

  • 2004/5: SE204: Lecture 1&2


    Main categories of java gui f ramework l.jpg
    Main categories of Java GUI Framework

    • Components:These are the building blocks of GUI based applications.

      Examples: JFrame, JButton, JLabel

    • Containers: A container is a component that holds other components.

      Examples: JFrame, JPanel, JWindow

    • Layout managers:These are used for laying out components in a container.

    2004/5: SE204: Lecture 1&2


    Main categories of java gui f ramework11 l.jpg
    Main categories of Java GUI Framework

    • Events: An action is translated into an EventObject. This object contains details about the event including type of action and where it occurred.

      Examples: key presses, button presses, mouse moves

    • Event Listeners: A class indicates which events it would like to receive. This is done by installing event listener objects.

    2004/5: SE204: Lecture 1&2


    Main categories of java gui f ramework12 l.jpg
    Main categories of Java GUI Framework

    • Graphics and Imaging classes:These are used for drawing and displaying images.

      Examples: Graphics, Color, Font, Rectangle, Image

    2004/5: SE204: Lecture 1&2


    Swing classes in uml notation l.jpg
    Swing classes in UML notation

    2004/5: SE204: Lecture 1&2


    Jframe l.jpg
    JFrame

    • A Frame object is an (optionally) resizable top-level window with

      • a title

      • a minimize box

      • a maximize box

      • a close box

  • JFrame is a direct extension of the AWT Frame class. The AWT Frame class extends the Window class

  • 2004/5: SE204: Lecture 1&2


    An example of a jframe l.jpg
    An Example of a JFrame

    2004/5: SE204: Lecture 1&2


    Using jframe l.jpg
    Using JFrame

    Let’s look at an example

    2004/5: SE204: Lecture 1&2


    Using jframe17 l.jpg
    Using JFrame

    Let’s look at another example

    2004/5: SE204: Lecture 1&2


    Slide18 l.jpg

    Both of the above programs give the same

    output

    2004/5: SE204: Lecture 1&2


    Another jframe example l.jpg
    Another JFrame Example

    2004/5: SE204: Lecture 1&2



    Slide21 l.jpg

    Now, lets look at the code

    • super(s);

      • this invokes the constructor of the parent superclass … the positioning of this is vital (it can/should only be done on the first line of the constructor method of the new subclass)

  • getContentPane().setBackground(Color.blue);

    • here, we use the Color blue to set the background colour, note the use of getContentPane(), this gives a reference to the JFrame’s container.

  • 2004/5: SE204: Lecture 1&2


    Slide22 l.jpg

  • setLocation(0,0);

    • specifies where to place the frame on the desktop

  • setVisible(true);

    • used to tell the screen to display the frame

  • 2004/5: SE204: Lecture 1&2


    The toolkit class l.jpg
    The Toolkit Class

    • This is an abstract class that provides an interface to platform specificdetails like window size, available fonts and images.

    • We never directly instantiate an object of type Toolkit. We obtain a toolkitobject by invoking the static getDefaultToolkit() method. This will give usan object that is appropriate for our system.

      Toolkit tk = Toolkit.getDefaultToolkit();

    2004/5: SE204: Lecture 1&2


    The toolkit class24 l.jpg
    The Toolkit Class

    • Situations where you might need to use a Toolkit

      • want to load an image file, use getImage()

      • want to obtain information about the screen, use getScreenSize()

      • want information about available fonts, use getFontList()

    2004/5: SE204: Lecture 1&2



    Slide26 l.jpg

    2004/5: SE204: Lecture 1&2


    Jpanel l.jpg
    JPanel

    • It is a component

    • It can contain other components

    • It can be structured using the layout managers

    • Constructors

      • JPanel() -- Creates a new JPanel with a FlowLayout

    2004/5: SE204: Lecture 1&2


    Using jpanel l.jpg
    Using JPanel

    2004/5: SE204: Lecture 1&2


    Slide29 l.jpg

    2004/5: SE204: Lecture 1&2



    Adding components l.jpg
    Adding Components

    • We will not try to learn everything about a particular user interfacecomponent.

    • It will be better if we try to understand the concepts and then we will beable to search the Java documentation for the details.

    • Adding a component to a container:

      1. Construct the component object

      2. Add it to the container

    2004/5: SE204: Lecture 1&2


    Using jbutton l.jpg
    Using JButton

    2004/5: SE204: Lecture 1&2


    Slide33 l.jpg

    2004/5: SE204: Lecture 1&2


    Slide34 l.jpg

    Now, lets look at the code

    • b1 = new JButton(“Button 1”);

      • creates an instance of JButton with the label “Button 1”

  • add(b1);

    • adds the JButton b1 to the container buttonPanel

  • getContentPane().add(p1);

    • adds the component p1 to the frame, note the use of getContentPane(), this gives a reference to the JFrame’s container.

  • 2004/5: SE204: Lecture 1&2


    ad