{ return Math.sqrt(dx*dx + dy*dy); } When the
{ return Math.sqrt(dx*dx + dy*dy); } When the Triangle class calls the draw method, it calls this new version of draw2ndLine and draws a line to the new third point. Further, it returns that new point to the draw method so it will draw the closing side of the triangle correctly. //draws 2nd line using saved new point public Point draw2ndLine(Graphics g, Point b, Point c) { g.drawLine(b.x, b.y, newc.x, newc.y); return newc; } The Triangle Drawing Program The main program simple creates instances of the triangles you want to draw. Then, it adds them to a Vector in the TPanel class. public TriangleDrawing() { super(”Draw triangles”); TPanel tp = new TPanel(); t = new stdTriangle(new Point(10,10), new Point(150,50), new Point(100, 75)); t1 = new stdTriangle(new Point(150,100), new Point(240,40), new Point(175, 150)); tp.addTriangle(t); //add to triangle list tp.addTriangle(t1); //in the TPanel getContentPane().add(tp); setSize(300, 200); setBackground(Color.white); setVisible(true); } It is the paint routine in this class that actually draws the triangles. class TPanel extends Jpanel { Vector triangles; public TPanel() { triangles = new Vector(); //list of triangles } //——————————————-public void addTriangle(Triangle t) { triangles.addElement(t); //add more to list } //——————————————-// draw all the triangles
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services