Container classes and objects - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Container classes and objects

Description:

Container classes and objects ... must be placed in a container, to be of any use. ContentPane is a special container that contains the current state of ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 16
Provided by: msresearch
Category:

less

Transcript and Presenter's Notes

Title: Container classes and objects


1
Container classes and objects
  • Objects that hold information in a dependable
    form, used by other classes

2
Color
  • Defined
  • Color boxColor new Color( )
  • boxColor Color.black
  • Used
  • g.setColor( boxColor )

3
Font
  • Defined (needs constructor info)
  • Font myFont new Font( Arial, Font.PLAIN, 12)
  • Used
  • g.setFont( myFont )
  • g.setColor( Color.red)
  • g.drawString( hello" ,160, 220)

Type
Style
Size
4
Polygon
  • Defined
  • int xValues 20, 40, 50, 30, 20, 15
  • int yValues 50, 50, 60, 80, 80, 60
  • Polygon shape1
  • new Polygon( xValues, yValues, 6 )
  • Used
  • g.drawPolygon( shape1 )

Number of points
5
A push-button object
  • JButton helloButton new JButton( "Hello" )
  • Where can we place the pushbutton?
  • On anything, really remember that!

6
  • import javax.swing.
  • import java.awt.
  • public class Button extends JFrame
  • public Button()
  • setSize(400,400)
  • JButton myButton new JButton(push")
  • add( myButton)
  • setVisible(true)
  • public static void main(String args )
  • Button app new Button()
  • // end class

7
JFrame methods summary
  • setSize (400, 400)
  • setLocation (50, 75)
  • add( someObject )
  • setDefaultCloseOperation( EXIT_ON_CLOSE )
  • setVisible( true )

8
Graphics method summary
  • paint (Graphics g)
  • g.setColor( boxColor )
  • g.fillArc( x, y, width, height, 0, 360 )
  • g.fillRect( x, y, width, height )
  • g.setFont( myFont )
  • g.drawString( hello" ,160, 220 )
  • g.drawPolygon( shape1 )
  • g.drawLine( x1,y1,x2,y2)

9
the Container class
  • Holds a whole window context frames, scroll
    bars, buttons, menus, pop-ups, and operator
    actions mouse clicks, dragging dropping.
  • Operator actions are called events.
  • JFrame objects must be placed in a container, to
    be of any use.
  • ContentPane is a special container that
    contains the current state of your computer.

10
A Container manages all PC resources
  • Its brilliant, really

Content current PC state
Layout presentation
Events operator actions
Container
11
Creating a ContentPane container
  • // a container to hold your computers info
  • Container myPC new Container()
  • // current state
  • myPC getContentPane( )
  • The Container myPC is now a Content
    environment, an Event environment, and a
    Layout environment
  • which is an object that holds the current details
    of all screen, user, keyboard, mouse events and
    conditions, and further... is a place where we
    can build a Graphical User Interface (GUI),
    compatible with the computers configuration.

12
what does this do?
  • Container myPC new Container()
  • myPC getContentPane( )
  • FlowLayout layout new FlowLayout( )
  • myPC.setLayout( layout )

JFrame
Container
13
Computers, it turns out, are just a bunch of
containers
Contaner your PC
ContentPane its current state
JFrame a graphics pane
Layout organizes the graphics
14
more JFrame and Container methods
  • setSize( w, h )
  • setLocation( x, y )
  • setDefaultCloseOperation( EXIT_ON_CLOSE )
  • Container myPC new Container()
  • myPC getContentPane()
  • FlowLayout layout new FlowLayout()
  • myPC.setLayout( layout )
  • JButton helloButton new JButton( "Hello" )
  • myPC.add( helloButton ) // note added to
    the Container
  • setVisible( true )

15
the Container controls everything
We now shift from using JFrame as the Graphics
organizer, to using the Container
Write a Comment
User Comments (0)
About PowerShow.com