JFrame vs Graphics - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

JFrame vs Graphics

Description:

then boxColor can be used to set System properties in Classes/Objects that need ... JColorChooser returns a Color object to the caller. Returns an Object? ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 15
Provided by: msresearch
Category:

less

Transcript and Presenter's Notes

Title: JFrame vs Graphics


1
JFrame vs Graphics
2
Color class
  • Like the String class, and Integer class, does
    not use the new keyword.
  • holds a color value (nothing more)
  • e.g Color boxColor new Color( )
  • boxColor Color.blue
  • or
  • Color boxColor Color.blue
  • then boxColor can be used to set System
    properties in Classes/Objects that need color
    (more later).

3
JColorChooser returns a Color object to the
caller
4
Returns an Object?
  • JColorChooser fills in all of the information in
    a blank object of the Color class, and copies it
    to the Color object in the calling statement
  • boxColor JColorChooser.showDialog(
  • null, Greeting, default color )

5
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
6
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
7
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)

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

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

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

11
the JFrame layouts and panels
  • Holds a whole window context frames, scroll
    bars, buttons, menus, pop-ups, and operator
    actions mouse clicks, dragging dropping.
  • Operator actions are called events.
  • "Controls" can be added to a frame.
  • JFrames are a type of Container.

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

JFrame and other Containers
Layout presentation
Events operator actions
Container
13
what does this do?
  • setLayout( new FlowLayout( ) )

14
more JFrame methods
  • setSize( w, h )
  • setLocation( x, y )
  • setDefaultCloseOperation( EXIT_ON_CLOSE )
  • setLayout( new FlowLayout( ) )
  • JButton helloButton new JButton( "Hello" )
  • add( helloButton )
  • setVisible( true )
Write a Comment
User Comments (0)
About PowerShow.com