Okay well, this is what I am working with. The following is an example of drawing polygon shapes:
/*
documentation section
program:DrawPolygon
name: msullivan
date: january.2011
*/
/* import statement section */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DrawPolygon extends JFrame
{
/* declaration section */
Color white = new Color(255, 255, 255);
Color black = new Color(0, 0, 0);
public DrawPolygon()
{
createUserInterface();
}
public void createUserInterface()
{
Container contentPane = getContentPane();
contentPane.setBackground(white);
contentPane.setLayout(null);
/* initialize components section */
setTitle("DrawPolygon");
setSize(400, 550);
setVisible(true);
}
/* main method */
public static void main(String[] args)
{
DrawPolygon application = new DrawPolygon();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(black);
Polygon diamond = new Polygon();
diamond.addPoint(200, 350);
diamond.addPoint(300, 400);
diamond.addPoint(200, 450);
diamond.addPoint(100, 400);
g.drawPolygon(diamond);
Polygon square = new Polygon();
square.addPoint(200, 100);
square.addPoint(300, 100);
square.addPoint(300, 200);
square.addPoint(100, 200);
g.drawPolygon(square);
Polygon triangle = new Polygon();
triangle.addPoint(200, 250);
triangle.addPoint(100, 300);
triangle.addPoint(300, 300);
g.drawPolygon(triangle);
Polygon rect = new Polygon();
rect.addPoint (100, 0);
rect.addPoint (550, 0);
rect.addPoint (200, 5);
rect.addpoint (30, 5);
g.drawPonygon(rect);
g.fillRect(100, 550, 200, 30);
}
}
My biggest issue is that the book isn't covering a lot of what the teacher wants me to do. For example, the first homework assignment incorporated code that was not even discussed in chapter 1 or 2.
What I don't understand right now is:
What defines the size of the document? i.e 300x300
What do I do to draw the shapes? These code examples above do indeed draw these shapes. However, do I absolutely need to trial and error coordinates or is there an easier way?
The code above shows me how to draw shapes. When I want to fill in these shapes, do I need to separate the drawing code from the painting code? Or can I just add a line to that shape to paint it?
This post was edited by nikkilina on Sep 16 2016 10:13pm