java - Why I have different results from run() method in two classes? -
first :
import acm.graphics.grect; import acm.program.graphicsprogram; public class graphtest extends graphicsprogram{ public void run(){ grect a= new grect(50, 50); add(a,50,50); } }
this show rectangle on screen.
second:
public class myprog extends program{ public void run(){ mycanvas canvas = new mycanvas(); add(canvas); } } import java.awt.event.*; import acm.graphics.*; public class mycanvas extends gcanvas implements componentlistener{ private grect rect; private static final double box_width = 50; private static final double box_height= 50; public mycanvas(){ addcomponentlistener(this); rect = new grect(box_width, box_height); rect.setfilled(false); add(rect,10,10); } public void update(){ grect rect2 = new grect(0.1*getwidth(), 0.1*getheight()); add(rect2,(getwidth()-box_width)/2,(getheight()-box_height)/2); } public void componentresized(componentevent e){update();} public void componenthidden(componentevent e){} public void componentmoved(componentevent e){} public void componentshown(componentevent e){} }
this supposed show me rectangle, doesn't. if use
init()
2 rectangles(rect
andrect2
) shows.
anyone can use example me understanding use of run()
, init()
, why have different results when i'm using run()
?
Comments
Post a Comment