CS110- Lecture 12 Mar 23, 2005 - PowerPoint PPT Presentation

About This Presentation
Title:

CS110- Lecture 12 Mar 23, 2005

Description:

The classes in a software system have various types of relationships to ... MTSO class is dependent on Tower class. Tower class is dependent on Location class ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 13
Provided by: Robert1138
Category:
Tags: cs110 | lecture | mar | tower

less

Transcript and Presenter's Notes

Title: CS110- Lecture 12 Mar 23, 2005


1
CS110- Lecture 12Mar 23, 2005
  • Agenda
  • Questions on Project 2?
  • Class dependencies
  • Components and Containers

2
Class dependencies
  • The classes in a software system have various
    types of relationships to each other.
  • We have seen many examples of dependency
    relationship in which one class uses another i.e.
    one class relies on another in some sense.
  • Often the methods of one class invokes the
    methods of another class.
  • Example
  • ChaosGame is dependent on Die class
  • MTSO class is dependent on Tower class
  • Tower class is dependent on Location class

3
Class Dependencies
  • Sometimes a class depends on itself i.e. an
    object of one class interacts with another object
    of the same class.
  • Example
  • Location class is dependent on itself because
    distance method needs another Location object.
    Header of distance method is
  • public double distance(Location other)

4
Class dependencies
  • Lets write a class ComplexNumber.
  • Instance data
  • Real part
  • Imaginary part
  • Methods
  • sum(ComplexNumber other)
  • prod(ComplexNumber other)
  • neg()
  • Various Setters and Getters

5
Components and Containers (Section 3.9)
  • We have used java capabilities to draw shapes
    using the Graphics and Color classes from
    standard library.
  • We wrote applets to draw shapes.
  • But we can also write applications (stand alone
    programs) with graphical components.
  • We need main method to run such applications.

6
Components and Containers
  • A GUI component is an object that represents a
    screen element that is used to display
    information or allow the user to interact with
    the program in a certain way.
  • GUI components include labels, buttons, text
    fields, radio buttons, check boxes and so on.

7
Components and Containers
  • GUI components and other GUI related classes are
    primarily in two packages
  • AWT Abstract windowing toolkit (old)
  • Components- Button, Label etc.
  • Other Classes Color etc.
  • Swing (New)
  • Components- JButton, JLabel etc.
  • Other classes Timer etc.
  • We will still use some classes of AWT such as
    Color.
  • But for components we will prefer using Swing
    Components.

8
Components and Containers
  • A Container is a special type of Component that
    is used to hold and organize other components.
  • AWT
  • Containers Frame, Panel etc.
  • Swing
  • Containers JFrame, JPanel etc.

9
Frames
  • Frame is a container that is used to display GUI
    based Java applications.
  • Frame is displayed as a separate window with its
    own title bar.
  • In can be resized, moved, maximized and
    minimized.
  • In swing Frame is defined by the JFrame class.

10
Panels
  • Panel is also a container. However it cannot be
    displayed at its own. A panel must be added to
    another container for it to be displayed.
  • Its primary role is to help organize the other
    components in a GUI.
  • In swing panel is defined by JPanel class.

11
Some Fundamental GUI components
  • Label
  • Displays a line of text.
  • In swing label is defined by JLabel class.
  • Button
  • Allows user to click at them and we can associate
    an action when button is clicked
  • In swing button is defined by JButton class

12
Frames and Panels
  • Lets write a class that gives us the following
    output.

Swing
Welcome to world of Swing Swing is Fun
OK
EXIT
Write a Comment
User Comments (0)
About PowerShow.com