Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

how to scroll string from left to right

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic