Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphical Interface Commands

Similar presentations


Presentation on theme: "Graphical Interface Commands"— Presentation transcript:

1 Graphical Interface Commands
By: Amir, Adam, Eduard Green text- good code Red text- bad code 

2 The Draw Panel J-Panel int workspaceWidth=1440, workspaceHeight=900;
Declare the drawpanel at the top of the code to be used MyDrawPanel drawpanel1; < (name of drawpanel can be anything, i.e. BobRossPanel1) Declare the size for the works space immediately underneath: int workspaceWidth=1440, workspaceHeight=900; Add the new Draw Panel to the J-Frame just like any other visible element: this.add (drawpanel1);

3 g2. line oval arc rectangle polygon draw/fill All the Shapes

4 Creating The Shapes g2.draw … g2.fill … Shapes and their properties:
The outcome will be the desired shape’s outline. (empty inside). g2.fill … The outcome will be the desired shape filled. (filled inside). Shapes and their properties: g2.drawLine(x of start point, y of start point, x of end point, y of end point) g2.drawRect(x of top left corner, y of top left corner, width, height) g2.drawOval(x of top left corner, y of top left corner, width, height) g2.drawArc(x, y, width, height, start angle, end angle)

5 Polygons are tricky but not really
Polygons are extremely useful because most shapes are polygons. When working with a polygon the x and y intercepts must be included in variable arrays above the created polygon. g2.drawPolygon(x-values array name, y-values array name, number of values in array/n) The x and y arrays must be declared as follows: int[]x8={first x value, second x value, third x value…}; int[]y8={first y value, second y value, third y value…}; Do not mess up the order of the x and y because they are coordinates to a point on the grid ad not separate.

6 Text To Draw To draw phrases or sentences the following code is used:
g2.drawString(“text”,x-location,y-location); Declare the font variable and name it: Font Cool = new Font("Haettenschweiler", Font.ITALIC, 40); Furthermore the text can be edited to the preferred size and font: g2.setFont(font variable name);

7 Color changes and size adaptations
When setting the color of the shape/outline you can follow 2 ways: Creating the color as a separate variable to be used repetitive times: Color colorrrr= new Color(r,g,b); Creating the color inside of the set color code that uses it: g2.setColor((new Color(r,g,b))); When setting the color all the shapes under the setColor line are affected, so it is ideal to revert the change so that not all the shapes have the same one.

8 Transformations in the drawing surface
Like math but easier The different changes of the graph positioning include: Rotation: g2.rotate(Math.toRadians(80)); Translation: g2.translate(+ x, + y); When dealing with rotations, the degrees are in radians. The rotation affects all the shapes underneath the line and therefore must be changed back to the original 0 radians to set the graph straight again.

9 Creating the grid, Cartesian plane
To make the calculations easier and to see the points on the drawPanel a grid can be used: How to make a grid is demonstrated on code…

10 The final touch To make the shapes smoother and the overall image look nicer the following two lines can be used: Graphics2D g2 = (Graphics2D)g; Converts the ordinay graphics object into a Graphics2d object. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); This line takes away the jaggedness and smooths out the lines.


Download ppt "Graphical Interface Commands"

Similar presentations


Ads by Google