Jframe vs graphics
Download
1 / 14

JFrame vs. Graphics - PowerPoint PPT Presentation


  • 344 Views
  • Uploaded on

JFrame vs Graphics 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

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 'JFrame vs. Graphics' - emily


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

Color class l.jpg
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).



Returns an object l.jpg
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 );


Slide5 l.jpg
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


Polygon l.jpg
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


Graphics method summary l.jpg
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);

}


A push button object l.jpg
A push-button object

JButton helloButton = new JButton( "Hello" );

Where can we place the pushbutton?

On anything, really… remember that!


Slide9 l.jpg

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


Jframe methods summary l.jpg
JFrame methods summary

  • setSize (400, 400);

  • setLocation (50, 75);

  • add( someObject )

  • setDefaultCloseOperation( EXIT_ON_CLOSE );

  • setVisible( true );


The jframe layouts and panels l.jpg
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.


A container manages all pc resources l.jpg
A “Container” manages all PC resources

  • It’s brilliant, really

JFrame and

other Containers

Layout –

presentation

Events – operator

actions

Container


What does this do l.jpg
what does this do?

setLayout( new FlowLayout( ) );


More jframe methods l.jpg
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 );


ad