Monday, March 5, 2012

Additional Info for 2nd Lesson

The following should be added to class Point.  The test function should become the tradition for every class to be coded in the future.


   void drawCross(Graphics g){
int sz = 3;
g.drawLine(x-sz, y, x+sz, y);
g.drawLine(x, y-sz, x, y+sz);
   }


   static void  test0(String path){
BufferedImage img = new BufferedImage(100,80,BufferedImage.TYPE_INT_RGB);
Point p1 = new Point(10,10);
Point p2 = new Point(20,30);
Graphics g = img.getGraphics();
g.setColor(Color.gray );
g.fillRect ( 0, 0, img.getWidth(), img.getHeight() );
g.setColor(Color.red );
p1.drawCross(g);
p2.drawCross(g);
try {
ImageIO.write(img, "PNG", new File(path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   }

No comments:

Post a Comment