Making a representation program.


125 views
Uploaded on:
Category: Funny / Jokes
Description
Making a design program Shading and Shapes Import libraries import javax.swing.*;/for JFrame import java.awt.*;/for Shading and Representation Program System open class myGrPgm develops JFrame {/expanding JFrame gives us: / -windows / -paint
Transcripts
Slide 1

Making an illustrations project Color and Shapes

Slide 2

Import libraries import javax.swing.*;/for JFrame import java.awt.*;/for Color and Graphics

Slide 3

Program Framework open class myGrPgm augments JFrame {/expanding JFrame gives us: / -windows / -paint / -utilization of Color }/end class myGrPgm

Slide 4

get a shading open Color palette = new Color ( 25, 120, 200 );/“palette” is a Color article //Color ( red, green , blue ); note: 25, 120, 200 is sea blue

Slide 5

how hues are characterized

Slide 6

an elucidation Color boxColor = Color.blue or Color boxColor = new Color( ); boxColor = Color.blue; object t to box Color.

Slide 7

Color class in Computer Memory Space Color boxColor = Color.blue utilizes library straightforwardly! JFrame library Color.blue Color.green Color.red Color.pink

Slide 8

Color class in Computer Memory Space Color boxColor = new Color( ); boxColor = Color.blue; Color.blue a duplicate! Color.green Color.red Color.pink prepared for Color Color.blue

Slide 9

include “the usual” fundamental open static void main(String args [ ]) { myGrPgm application = new myGrPgm( ); }/causes a constructor to be run

Slide 10

so far… import javax.swing.*;/for JFrame import java.awt.*;/for Color and Graphics open class myGrPgm broadens JFrame { open Color palette = new Color ( 25, 120, 200 );/genuine work completes here open static void main(String args [ ]) { myGrPgm application = new myGrPgm( ); }/end class myGrPgm

Slide 11

a constructor/sets up a “Frame” open myGrPgm( ) { setSize( 400, 400 ); setLocation( 20, 40 ); setDefaultCloseOperation( EXIT_ON_CLOSE ); setVisible( genuine ); }/utilizes JFrame techniques, on the grounds that WE are JFrame/i.e. “this” class we’re in is a JFrame youngster

Slide 12

representation on a PC X course ( 0, 0 ) ( 1024, 0 ) ( ?, ? ) y heading ( 0, 768 ) ( 1024, 768 )

Slide 13

a superior constructor/sets up a “Frame” open myGrPgm( int width, int tallness ) { setSize( width, stature ); setLocation( 20, 40 ); setDefaultCloseOperation( EXIT_ON_CLOSE ); setVisible( genuine ); }/utilizes JFrame systems, in light of the fact that WE are JFrame/i.e. “this” class we’re in is a JFrame kid

Slide 14

change main open static void main(String args [ ]) { myGrPgm application = new myGrPgm( 400, 400 ); } supplied to constructor

Slide 15

so far… import javax.swing.*;/for JFrame import java.awt.*;/for Color and Graphics open class myGrPgm develops JFrame { open Color palette = new Color ( 25, 120, 200 ); open myGrPgm( int width, int stature ) { setSize( width, tallness ); setLocation( 20, 40 ); setDefaultCloseOperation( EXIT_ON_CLOSE ); setVisible( genuine ); } open static void main(String args [ ]) { myGrPgm application = new myGrPgm( 400, 400 ); }/end class myGrPgm

Slide 16

last strategy being a JFrame, implies that we can USE JFrame routines like “ setLocation( … ” being a JFrame, implies that we can re-compose systems that are IN JFrame for more power, as “ paint( … ”

Slide 17

what is paint? a system in JFrame it’s a “void” technique (returns nothing to the guest ); called by the PC naturally that we re-compose (“override”) that another person composed that uses a Graphics partner class that puts hues and shapes in a JFrame

Slide 18

Graphics aide class? gaze upward the Graphics class on the Sun Java site It must be utilized by a paint system as a part of a JFrame class it contains variables and strategies for its own, to shading and draw shapes

Slide 19

structure of a paint strategy open void paint( Graphics g )/g is the Graphics duplicate (item) {/set a shading g. setColor( pallette );/do something with the shading/g.fillRect( x, y, width, stature ); g.fillRect( 50, 100, 200, 200 ); }

Slide 20

setting a shading utilize our open shading “pallette” or utilize an essential shading g.setColor( Color.green );

Slide 21

serves to set the foundation/make width and tallness open, and static open static int winHeight = 400 open static int winWidth = 400;/use in paint, or wherever you require window size: open void paint( Graphics g ) {/set foundation g.setColor( Color.white ); g.fillRect( 0, 0, winHeight, winWidth ); g.setColor( palette ); g.fillRect( 50, 100, 200, 200 ); }

Slide 22

static? at whatever point you choose something is one of a kind, will never be anything with the same name anyplace in your program primary is static any variable or strategy utilized by principle must be static

Slide 23

use winHeight and winWidth open static void fundamental( String args [ ] ) { myGrPgm application = new myGrPgm( winHeight, winWidth ); }

Slide 24

demo see the myGrPrm illustration

Slide 25

Using Arrays to draw shapes int xValues[] = { 245, 245, 260, 260, 230, 230 }; int yValues[] = { 250, 300, 300, 310, 310, 250 }; g.setColor( Color.yellow ); g.fillPolygon ( xValues, yValues, 6 );/comes to an obvious conclusion

Slide 26

Arrays are arrangements of numbers int xValues[] = { 245, 245, 260, 260, 230, 230 }; xValue[ 0 ] is 245 xValue[ 1 ] is 245 xValue[ 2 ] is 260 xValue[ 3 ] is 260 xValue[ 4 ] is 230 xValue[ 5 ] is 230

Slide 27

A method for sorting out variables int myArray[ ] = { 41, 16, 55, 26, 30, 0 }; myArray is a rundown of 6 ints The ints are “indexed” 0 through

Recommended
View more...