This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the position of component in applet

 
Jeannie Yong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am designing a GUI with applet. In my GUI, a picture will move from left to right. I gave the positon(0,0) as the start point, but when I run it, it doesn't seem that that picture start at (0,0). Is there any suggestion about it?
Thanks a lot.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeannie,
It might be more helpful to tell us what the problem actually is.
For example:
The image always starts at 10,10 even though I am telling it to be at 0,0 ...
Some code might even be helpful ...
Regards,
Manfred.
 
Jeannie Yong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following is part of my code. I tried to show two moving images in this page. One of the image will move from left top corner to bottom right corner. The other one is moving from bottom right corner to top left corner. The width of applet is 800 and the height of applet is 650. After I run the follwing code, one image always come from left middle instead left top. The other one come from right middle instead right bottom. So I don't know what happened to my code.
Thanks.
void DrawCondition2(int randomaxis, int randomCount,int ifDrawBall)
{
if(randomaxis == MOVE_STYLE_2)
{
x1pos = 0;
y1pos = 50;
x2pos = 700;
y2pos = 650;
}
else
{
x1pos = 0;
y1pos = 450;
x2pos = 700;
y2pos = 200;
}
twoImages = true;
randomCount = randomInt(60);
currentImg=FilterImage[randomCount];
if(randomCount < 99)
randomCount = randomCount + 1;
//randomCount = FilterImage[randomCount];
currentImg2=FilterImage[randomCount];
beforeTime = System.currentTimeMillis();
for(int n = 0; n < NUM_FRAMES_PER_LOOP; n++)
{
if(n == 14)
{
if (ifDrawBall!=0)
drawBall=true;
if(drawBall)
{
drawBallInit(randomInt(800),randomInt(650));
repaint();
}
}
if((answer != 2)&& (answer < 3))
{
// repaint();
// pause(500);
System.out.println("answer is: " + answer);
System.out.println("the response time is: " + (afterTime-beforeTime));
//continue;
break;
}
repaint();
pause(150);
if(randomaxis == 1)
{
x1pos = x1pos + 25;
x2pos = x2pos -25;
}
else
{
x1pos = x1pos + 25;
y1pos = y1pos + 25;
x2pos = x2pos - 25;
y2pos = y2pos - 25;
}
}
//afterTime = System.currentTimeMillis();
//System.out.println("the time to show the image is : " + (afterTime-beforeTime));
}
 
Jeannie Yong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forgot about this question. I already figured out what's wrong with my code. But I have another question about applet. When I tried to show a moving picture in a applet, the picture always flash. I call repaint() several times to let the picture move, is it the reason why picture flash? Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic