• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphic problem please help

 
ks goh
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i have paint method and i'm able to get the correct result.
but problem is when some other windows go over the graphic windows,
the graphic will be lost and i need to repaint again.
is there anyway to solve it?

public void paint(Graphics g){
if(initial){
initial = false;
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
for(int x=0; x<XWidth; x++){
for(int y=0; y<YHeight; y++){
g.drawImage(Junctionimage,baseX+(x*50),baseY+(y*50),50,50,this);
g.drawImage(CarImage,baseX+(99*50),baseY+(((YHeight-1)*50) -(99*50)),50,50,this);
g.drawImage(ObstacleImage,15+(99*50),15+(((YHeight-1)*50) -(99*50)),20,20,this);
g.drawImage(startingEndingImage,15+(99*50),15+(((YHeight-1)*50) -(99*50)),20,20,this);
g.drawImage(vrouteImage,15+(99*50),15+(((YHeight-1)*50) -(99*50)),20,20,this);
g.drawImage(hrouteImage,15+(99*50),15+(((YHeight-1)*50) -(99*50)),20,20,this);
}
}
g.drawImage(CarImage,baseX+(99*50),baseY+(((YHeight-1)*50) -(99*50)),50,50,this);
g.drawImage(ObstacleImage,15+(99*50),15+(((YHeight-1)*50) -(99*50)),20,20,this);
}
if(UpdateCar){
g.drawImage(Junctionimage,baseX+(previousX*50),baseY+(((YHeight-1)*50) -(previousY*50)),50,50,this);
g.drawImage(CarImage,baseX+(currentX*50),baseY+(((YHeight-1)*50) -(currentY*50)),50,50,this);
UpdateCar = false;
}
if(UpdateObstacle){
g.drawImage(ObstacleImage,15+(obstacleX*50),15+(((YHeight-1)*50) -(obstacleY*50)),20,20,this);
UpdateObstacle = false;
}
if(UpdateObstacleList){
for(int x=0; x<obstacleList.size(); x++){
Coordinate coordinate = (Coordinate)obstacleList.elementAt(x);
g.drawImage(ObstacleImage,15+(coordinate.x*50),15+(((YHeight-1)*50) -(coordinate.y*50)),20,20,this);
}
UpdateObstacleList = false;
}
if(UpdateStartingEnding){
g.drawImage(startingEndingImage,baseX+(ReceiveX*50),baseY+(((YHeight-1)*50) -(ReceiveY*50)),50,50,this);
g.drawImage(startingEndingImage,baseX+(ReceiveX1*50),baseY+(((YHeight-1)*50) -(ReceiveY1*50)),50,50,this);
UpdateStartingEnding = false;
}
if(UpdateRoute){
for(int x=0; x<shortestList.size()-1; x++){
C1 = (Coordinate)shortestList.elementAt(x);
C2 = (Coordinate)shortestList.elementAt(x+1);
if(C1.compareForHorizontalVertiacal(C2.x,C2.y)){
if(C1.compareForLeftRight(C2.x,C2.y))
g.drawImage(hrouteImage,25+(C1.x*50),14+(((YHeight-1)*50) -(C1.y*50)),60,20,this);
else
g.drawImage(hrouteImage,-25+(C1.x*50),14+(((YHeight-1)*50) -(C1.y*50)),60,20,this);
}
else{
if(C1.compareForUpDown(C2.x,C2.y))
g.drawImage(vrouteImage,15+(C1.x*50),-35+(((YHeight-1)*50) -(C1.y*50)),20,60,this);
else
g.drawImage(vrouteImage,15+(C1.x*50),20+(((YHeight-1)*50) -(C1.y*50)),20,60,this);
}
UpdateRoute = false;
}
}
}
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ks goh:
hi i have paint method and i'm able to get the correct result.
but problem is when some other windows go over the graphic windows,
the graphic will be lost and i need to repaint again.
is there anyway to solve it?


I'm not sure what you mean by "solve it" but it
was designed to work the way you describe. What
you do in paint() is ephemeral, and when part or
all of it needs to be drawn again it calls your
paint() method automatically.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!