se204 object oriented development
Download
Skip this Video
Download Presentation
SE204 Object-Oriented Development

Loading in 2 Seconds...

play fullscreen
1 / 34

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


  • 454 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

SE204 Object-Oriented Development

Jacqueline McQuillan B.Sc.

NUI Maynooth

overview
Overview
  • Java Graphics
  • Threads
  • I/O in Java
  • Object Serialization
  • Remote Method Invocation (RMI)
  • More …

2004/5: SE204: Lecture 1&2

basic java graphics
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
A Simple Example

2004/5: SE204: Lecture 1&2

another example
Another Example

2004/5: SE204: Lecture 1&2

graphical user interface
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
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
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
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
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
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
Swing classes in UML notation

2004/5: SE204: Lecture 1&2

jframe
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
An Example of a JFrame

2004/5: SE204: Lecture 1&2

using jframe
Using JFrame

Let’s look at an example

2004/5: SE204: Lecture 1&2

using jframe17
Using JFrame

Let’s look at another example

2004/5: SE204: Lecture 1&2

slide18
Both of the above programs give the same

output

2004/5: SE204: Lecture 1&2

another jframe example
Another JFrame Example

2004/5: SE204: Lecture 1&2

slide21
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
setSize(250, 100);
      • specifies the width and height of theframe in pixels
  • 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
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
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

jpanel
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
Using JPanel

2004/5: SE204: Lecture 1&2

adding components
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
Using JButton

2004/5: SE204: Lecture 1&2

slide34
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