Painting - PowerPoint PPT Presentation

Painting l.jpg
Download
1 / 16

Painting. Paint() and the Graphics Context. Painting. Many components (buttons, scroll bars, etc.) have their appearance determined by the underlying window system. However, applets, frames, panels and canvases, have no given appearance

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Download Presentation

Painting

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


Painting l.jpg

Painting

Paint() and the Graphics Context


Painting2 l.jpg

Painting

  • Many components (buttons, scroll bars, etc.) have their appearance determined by the underlying window system.

  • However, applets, frames, panels and canvases, have no given appearance

  • Overloading the paint() method allows us to draw on these components


Painting3 l.jpg

Painting

  • Painting a component is done by making calls to a graphics context

    • For example, g.setColor(Color.BLUE);

  • Graphics context

    • Is an instance of the Graphics class

    • Knows how to render onto a single target.


Painting4 l.jpg

Painting

  • The four major operations provided by the Graphics class:

    • Selecting a color

    • Selecting a font

    • Drawing and filling

    • Clipping


Selecting a color l.jpg

Selecting a Color

  • There are 13 predefined colors E.g., Color.black, Color.red, Color.blue

  • If you want a new color:

    • New Color(R,G,B)

    • Color c = new Color(255, 0, 0); //red

    • g.setColor(c);

  • Call SUBSEQUENT ops will be color c


Selecting a font l.jpg

Selecting a Font

  • Three fonts are platform independent

    • Serif

    • SansSerif

    • Monospaced

  • Font f = new Fone(“SansSerif”, Font.BOLD + Font.ITALIC, 24);

  • g.setFont(f);


Drawing and filling l.jpg

Drawing and Filling

  • Component coordinate system

    • Point (0,0) is upper-left.

  • The Graphic Context methods:

    • drawLine()

    • drawRect(), fillRect()

    • drawOval(), fillOval()

    • drawArc(),


Drawing and filling8 l.jpg

Drawing and filling

  • drawPolygon()

  • drawPolyline()

  • drawString()


Drawline x1 y1 x2 y2 l.jpg

drawLine(x1,y1,x2,y2)

  • Public void drawLine(int x1, int y1, int x2, int y2);

  • g.drawLine (0,0, 100, 50);


Drawrect and fillrect l.jpg

drawRect and fillRect

  • Public void fillRect(int x, int y, int width, int height);

  • g.fillRect(20, 25, 100, 80);


Drawoval and filloval l.jpg

drawOval and fillOval

  • An oval is specified by a rectangular bound ing box

  • To draw a circle, use a square bounding box.


Drawpolyline l.jpg

drawPolyline()

  • drawPolyline(int x[], int y[], int numberOfPoints);

  • int pX[] = {20,150,150};

  • int pY[] = {20,20,120};

  • g.drawPolyline (pX, pY, 3);


Clipping l.jpg

Clipping

  • g.setClip(x, y, width, height);


Gui thread l.jpg

GUI thread

  • The Java runtime enviroment creates and controls threads behind the scenes.

  • One of these threads is the GUI thread.

  • It accepts user input (mouse) and calls the paint() method


Spontaneous painting l.jpg

Spontaneous Painting

  • The GUI thread spontaneously calls paint() whenever a component is

    • de-iconificatication

    • After first display


Repaint l.jpg

repaint()

  • If you want to paint something (add a mark to the screen) after a mouse click, do you place the code in the mouse event handler?


  • Login