Preview

Theory Solution

Good Essays
Open Document
Open Document
999 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Theory Solution
1 Describe the graphical coordinate system in Java. Where is the origin? What units apply to the x,y coordinates?

Java AWT Graphic component is different with respect to x and y coordinate that we have learnt in math. It defines its own coordinate system to specify where and how drawing operation will take place. Here the origin (0,0) is at the top left corner of the component. Here X coordinate increases as we move right and Y coordinate increases as we move down. . The units for X and Y is in pixels.

1. How would you use the Graphics class to draw a line between 2 specific points? Give an example.

To draw a line between 2 points using Java graphics we use a drawLine() method of the graphics class.
Example:
public void draw(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}
Here the starting point will be (x1,y1) and ending point will be (x2,y2)

2. How do you specify a particular color to be used as fill when using the Graphics class?

Suppose we made a rectangle using the drawRect() method of the graphics class. public void draw(Graphics g)
{
//Rectangle starting point at (100,100) with a height and widht of 80 each
g.drawRect(100,100,80,80);
}
To fill it with a particulat color we first set the color and then call fillRect() method as shown below: public void draw(Graphics g)
{
//Rectangle starting point at (100,100) with a height and width of 80 each
g.drawRect(100,100,80,80);
g.setColor(Color.RED);
g.fillRect(100,100,80,80);
}

3. How would you create a SanSerif font of point size 14 that is bold and italic? Give an example.

public void setFontBoldItalic(Graphics g)
{
Font font=new Font(“SansSerif”, Font.BOLD | Font.ITALIC, 14);
g.setFont(font);
}

4. Given a graphics object g, write a few lines of code to have that graphics object draw a green circle (filled in) that has a diameter of 100 pixels.

public void draw(Graphics g)
{
//Circle starting point at (25,25) with a diameter of 100pixels

You May Also Find These Documents Helpful

  • Satisfactory Essays

    1. Name three different kinds of graphs that are often used to plot information and discuss the value of each.…

    • 334 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Comp3652 Unit 2 Assignment

    • 1090 Words
    • 5 Pages

    Although graphics are involved in this assignment, you will not need to implement your own graphics…

    • 1090 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    I will then compare the limitations of different software packages used in graphics work. (M1)…

    • 3549 Words
    • 15 Pages
    Powerful Essays
  • Good Essays

    CH3 GIS

    • 473 Words
    • 2 Pages

    5. What is a geographic coordinate system, and why is it a poor choice for creating maps?…

    • 473 Words
    • 2 Pages
    Good Essays
  • Good Essays

    A1: Applet is a type of Java program that runs on web browser. It can be a fully functional Java application because it has full Java API…

    • 559 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Unit 9 P1

    • 481 Words
    • 2 Pages

    For 2A.P1: learners are required to review two graphic products created by others. Learners should explain features of the products, the technical qualities, the content, audience and purpose. Features should include composition, use of colour, size and position. The two graphic products should be designed for different purposes.…

    • 481 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Slope Essay For years Mathematicians have studied and found various mathematical equations. One thing they've came across is numerous equations for slope. You maybe asking, what is slope? Slope is rise over run.To find slope (m=slope) on a graph, you draw and label your x (horizontal) and y (vertical) axis on a xy-coordinate plane. When you draw your two lines they should meet at right angles at a point zero. The axis is divided into four quadrants. Then you find any two points ( (0,0) and (2,1) ) on a line and calculate rise over run (m=2/1). Plot the point on the designated spot which you have calculated.To find the slope of a line using the coordinates of two points, you find to points using the formula: y-y /x-x . Take the y's and subtract them, then take the x's and subtract them. Then that's your slope. If it turns out to be zero its no slope and if zero is on the bottom of the fraction it is then called null set, which means a set with no numbers.Next, you can also find slope by using slope-intercept form, which you us the equation y=mx+b. M = slope, b = y-intercept, and x and y are your points. You will take your slope and plug it into the m and then take the y-intercept and plug it into b. You want to get your y and x on the same side. You can subtract the x to get it over on the y side or you can subtract the y and get in on the x side. Then on one side you should have just a number. It's best to subtract from the side with one variable and one number. The answer should always be in standard form.Last, but not least you can also find slope using a line by the standard form equation.(y, y )= m(x, x ) is the standard form equation. There are many ways you can use this equation, to find slope of two points, given a slope and a point, given slope and y-intercept, and slope of parallel and perpendicular lines. In standard form the number before X has to be positive. Also to write an equation you have to know slope and a point. When finding an equation in…

    • 625 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    104 demand

    • 268 Words
    • 1 Page

    Use the data generator in the lesson, to get data to plot on your graph. Create the graph and plot out the points given to you. Be sure to label all parts of the graph and give it a title. The easiest way to create your graph is to do it by hand. Draw your graph out on paper, after you have completed all of the steps use a digital camera to take a picture of it. Save your graph to your computer and insert it as a picture at the top of this document.…

    • 268 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    Chromatograph Lab

    • 320 Words
    • 2 Pages

    4. The combination of colors used to make black are all sorts of colors combined. They could be blue, green, grey, and brown.…

    • 320 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Problems1

    • 605 Words
    • 2 Pages

    the three points (0, 1), (0.5, 2) and (1, 4). Plot the resulting spline (you may use the file…

    • 605 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Cartesian Graph

    • 338 Words
    • 2 Pages

    Imagine that a line on a Cartesian graph is approximately the distance y in feet a person walks in x hours. What does the slope of this line represent? How is this graph useful? Provide another example for your colleagues to explain.…

    • 338 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Candy Chromatography

    • 625 Words
    • 3 Pages

    5. Dip toothpick into a sample colored water, dab the color onto the pencil. Repeat using another toothpick for the following colors. Allow filter paper to dry, go back and add MORE color to the following dots.…

    • 625 Words
    • 3 Pages
    Good Essays
  • Good Essays

    12

    • 389 Words
    • 2 Pages

    • The image can only contain the colors red, yellow, blue, black, white, and gray.…

    • 389 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Trust Fall Research Paper

    • 1589 Words
    • 7 Pages

    You and your partner will decide who will be doing the drawing and who will be giving instructions. The person drawing will have a pencil and a blank paper. The person giving directions will receive a picture. The person giving instructions will have to give directions to the person drawing so that they can recreate the original picture. The person giving directions is the only one allowed to talk, he can only give directions in shapes and lines. For example, you could not just say,”Draw a house”. Once you both think you are done, you can compare the drawn picture to the original one.…

    • 1589 Words
    • 7 Pages
    Good Essays
  • Satisfactory Essays

    (b) What is a 4GL? Give two examples of 4GL. Discuss the relative advantages and disadvantages of 4GLs in software development. (5)…

    • 654 Words
    • 3 Pages
    Satisfactory Essays

Related Topics