• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

simple animation

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have project due that requires me to write a couple of sorting algorithms and display them graphicly sorting, some sort of little animation. I have written them sorting algorithms out but i have never used the animation/drawing part of Java, so do quite know where to start. What i would like to is diplay the numbers on screen maybe with a big font and in color and have a graphical representation of what the sorting algorithm is actually doing.
like for instance i would like to display the array of numbers:
10 6 200 5 11 ....
then have the number that is being sorted float to its position.
200
10 6 5 11
and then land
200 10 6 5 11
my question is what is the best way to get started do i use awt or swing? how do i make my text big an color it? and how do i do the animation part?
any help would be great.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple comments:
I would use Swing over AWT, definitely.
If you are creating your GUI by laying out components (and maybe moving them around), use JLabels. You can call setFont and setForeground on them for size and color.
If you are doing animation by customizing the painting (display) of a panel (JPanel), use the setColor method on Graphics2D, as well as a host of other things you could do there.
How you do the animation depends on how complicated your GUI needs to be. Probably, however, you should control it with a System time-based counter running in a separate thread that updates your display every X milliseconds.

Bill
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to take a look at the threads section of Sun's Java Tutorial for a simple example of animated sorting that you could replicate.
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the help but the applets dont seem to work for me it looks like a distorted television. Anyway do you know if i use ImageIcon could i write over the image such as placing a number over the image. and also since i can place an ImageIcon on a JLabel can i move it?
Once again thanks for the help.
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic