Presentation is loading. Please wait.

Presentation is loading. Please wait.

Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the.

Similar presentations


Presentation on theme: "Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the."— Presentation transcript:

1 Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the 3 dots next to the Command box, then find your jdk folder, then bin, then select appletviewer. 6)OK, Apply, OK

2 Intro to Graphics Graphics are often created using an applet An applet is simply a Java program that is embedded in an HTML document, and (usually) is designed to be Web-accessible You must compile an applet file before embedding it in an HTML file (the HTML file only takes the bytecode, which can then be run using any browser – this is one of Java’s major advantages over other languages) Applet files… –Have no main –Import 2 or more packages –Must extend the class called Applet –Once embedded, can be viewed with a browser or appletviewer

3 To draw graphics, define the paint method that is inherited from Applet The paint method accepts one parameter, of type Graphics Using the Graphics object, you can draw using methods such as drawRect( ), drawOval( ), drawLine( ), etc. Java uses an xy-coordinate system, with the top-left corner being the origin (0,0) When drawing shapes, you pass parameters specifying where to begin the shape, and how far to draw it. Example: page.drawRect(100,100,80,50) /* draws a rectangle starting at (100,100) and with length=80 and height=50. page is the Graphics object */ Demo….GraphicsDemo

4 To draw a line: drawLine(startX,startY,endX,endY) // note how this is different from rectangles! –Demo… To draw an oval, you specify the dimensions of its bounding rectangle, the rectangle that it would fit into To draw a circle: the bounding rectangle must have equal sides (a square) –Demo… To draw an arc (part of a circle): like drawing an oval, but also give the starting angle and the measure of the angle –Demo…

5 To write text: drawString(String,x,y) // x,y is bottom left with Strings!! Demo…. The Color class has a bunch of predefined colors, such as Color.yellow and Color.red (see list on p 106) You can set the background by simply typing setBackground(Color), but to set a shape’s color, you must use the Graphics object (i.e. page.setColor(Color.Blue) )

6 Assignments Copy & Paste Snowman from the student folder P. 118 # 14 (try to avoid using MID and TOP) P. 118 # 15 Create a drawing of your own – be creative, and experiment with all of the methods of the Graphics class that we learned.


Download ppt "Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the."

Similar presentations


Ads by Google