• 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

Graphics Solution

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, can somebody help me?

Everytime I click the Frame, the yellow "1" appers, but I want now, that evertime comes a new "1" out. So that more than one "1" is shown.
Thanks!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you need a data structure -possibly an ArrayList- to keep track of all 1s that are currently displayed, and the drawing code needs to be aware that there can be more than one. if the button is pressed, a new one is added to the list, and once it reaches the bottom it is removed from it.

You could use a java.awt.Point object for the individual numbers (unless each number can have its own value and color, in which case you need to create your own class that can hold those values in addition to x and y position).

In the most basic case you'd have a data type like: List<Point> numbers = new ArrayList<Point>()
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Don't call repaint() either of the same component or another in its UI hierearchy from within a painting method override.
2. Don't compare a boolean variable to a boolean literal.
3. Learn and follow the Java coding conventions in respect of vertical and horizontal whitespace and placement of braces.
4. Don't write multiple statements on one line.

Also, detecting a mousePressed (or released) is usually more reliable than detecting mouseClicked, which is only triggered when the press and release are within a system-defined radius (sometimes 0). And do you have a reason for attempting to fill a rectangle 30000 pixels square? which you can't of course as the Graphics' clip will be much smaller than that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic