jframe vs graphics l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
JFrame vs Graphics PowerPoint Presentation
Download Presentation
JFrame vs Graphics

Loading in 2 Seconds...

play fullscreen
1 / 14

JFrame vs Graphics - PowerPoint PPT Presentation


  • 355 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
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
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
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
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
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
A push-button object

JButton helloButton = new JButton( "Hello" );

Where can we place the pushbutton?

On anything, really… remember that!

slide9
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
JFrame methods summary
  • setSize (400, 400);
  • setLocation (50, 75);
  • add( someObject )
  • setDefaultCloseOperation( EXIT_ON_CLOSE );
  • setVisible( true );
the jframe layouts and panels
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
A “Container” manages all PC resources
  • It’s brilliant, really

JFrame and

other Containers

Layout –

presentation

Events – operator

actions

Container

what does this do
what does this do?

setLayout( new FlowLayout( ) );

more jframe methods
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 );