This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Action perform GUI problem  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been working on a project that is basically simulating a text based game. The problem I have is in my action performed method in my GUI class.

The method


has two input parameters. A String for the item meaning it checks if the String is equivalent to "pencil", and an int for the number of times.

The action perform method

 
Steven Villarreal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
requires a String and an int, what would I place in the parenthesis next to "pencil", ?
 
Sheriff
Posts: 24295
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to say "You have broken the pencil into 42 pieces". So where in your design would you find the number 42?
 
Steven Villarreal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the only time I mention the variable "times" in my program.
 
Paul Clapham
Sheriff
Posts: 24295
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. In that case there's no point in telling somebody how many times they broke the pencil if there's nothing in your design which records that number, is there?

On the other hand if you really want to tell them that, then you'd need to change your design to include pencil-breaking events, or something like that.
 
Steven Villarreal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes sense. I could use a JOption pane for that so I could ask them to input a number.
 
Marshal
Posts: 63843
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are better ways to get a number than option pane, which is very old‑fashioned. Try a Scanner instead.
 
Paul Clapham
Sheriff
Posts: 24295
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:There are better ways to get a number than option pane, which is very old‑fashioned. Try a Scanner instead.



You could, but Steven's original post mentions a "GUI" class. To me that suggests that there's some Swing code -- and the existence of an actionPerformed(ActionEvent) method makes that even more likely. However this would make a JOptionPane also, how can I put this, not the right sort of thing to do.

If there's supposed to be something about pencil-breaking in the design then the GUI should reflect that feature via standard GUI controls.
 
Rancher
Posts: 3127
110
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or maybe the breaking of a pencil results in a random number of pieces, in which case OP might use the Random class
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!