• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to scroll string from left to right

 
divya chamarti
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any body help me to tell the how to scroll a string from left to right ?
like from right to left there is a method drawString(-,-,-); in Graphics class
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can scroll a string by painting it, waiting a bit, then erasing it (by drawing it in the background color), and drawing it again at a different X position. The methods to use would always be the same, just with different parameters.

Instead of drawing and then erasing you could also look into the concepts of "double-buffering" and "offscreen drawing".
 
divya chamarti
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LIKE scrolling from right to left we are providing th ecode shown below
g.drawString(text, x, y);
for left to right can any body provide the code???
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
drawString does not scroll, it simply paints the text at a particular position. If you use successively larger X values, it scrolls to the right, if you use successively smaller X values it scrolls to the left.
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by divya chamarti:
LIKE scrolling from right to left we are providing th ecode shown below
g.drawString(text, x, y);
for left to right can any body provide the code???


Well I will not give you the solution as JAVA Ranchers doesn't provide Homework consultancy.. come up with some homework...

Well I just give you an idea..the idea is same as Ulf told you..


You can scroll a string by painting it, waiting a bit, then erasing it (by drawing it in the background color), and drawing it again at a different X position. The methods to use would always be the same, just with different parameters.

Instead of drawing and then erasing you could also look into the concepts of "double-buffering" and "offscreen drawing".


try to make an applet thread where you show your string and then move it further and erase the last image drawn use a thread where you can write your method in run() method.

Well Ulf, I can code in simple way by use of threading but now I am curious about Double Buffering and Offscreen Drawing. I request you to pls throw some light on "Double Buffering" and "Offscreen Drawing"...

I am not telling you to give code. But throw some light on fundamentals..of these two technologies..
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As almost always if you want to research something, Google and Wikipedia are your friends. The following links came up right away:

http://en.wikipedia.org/wiki/Double_buffering

http://www.realapplets.com/tutorial/DoubleBuffering.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic