• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphics Solution  RSS feed

 
Steven Joost
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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>()
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!