Programming project

iaangrammy12
FinalDrawingComponent.java

package gradeStudentWork; import java.awt.*; import java.util.*; import javax.swing.*; public class FinalDrawingComponent extends JComponent { //declare Color arrayList or three different //ArrayLists for R, G, B here //Point is an object that has two properties x and y private ArrayList<Point> values; //Constructor public FinalDrawingComponent(){ values = new ArrayList<Point>(); } //accepting x, y values from FinalDrawingViewer.java public void appendValues(int x, int y){ values.add(new Point(x,y));//add a new Point to draw repaint();//call paintcomponent to redraw } public void clearArray(){ values.clear(); repaint(); } //modify this method to accept colors from //the text file in FinalDrawingViewer.java //to set the foreground color public void changeColor(){ int red = (int) (Math.random() * 256); int green = (int) (Math.random() * 256); int blue = (int) (Math.random() * 256); this.setForeground(new Color(red,green,blue)); //clearArray();//this may be important to add later...can you tell why? } @Override public void paintComponent(Graphics g) { //drawing the back ground with the foreground //color set in changeColor g.fillRect(0, 0, getWidth(), getHeight()); for (int i=0; i< values.size(); i++){ int x = values.get(i).x;//getting x value of Point i int y = values.get(i).y;//getting y value of Point i Color c = new Color(255,0,0); g.setColor(c); g.fillOval(x, y, 10, 10); } } }