• 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

My first simple program, really need some pointers

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok this is my first simple program, I know its probs a bit wrong but its working. If anyone could point out how it could be done easier feel free to comment.
The program is taking inventory numbers and changing them, then writing to a jTable..
A few questions i do have is...

How would i go about Using each players Inventory in a different class or package...

How would i got about Adding a Jframe with a button that runs the program...

If any ways to simplify my code would be great thanks

Heres my code


 
Saloon Keeper
Posts: 10834
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest separating the user interface code from the game logic. You should work on the game logic first using a simple text user interface. Then after you have the game logic in place and debugged, add the GUI on top of it.

Review your requirements. Nouns will become classes (e.g. 'Player'), and verbs will become methods. Look for noun relationships, such as a Game having two (or more) Players.

Your main() method should have very few lines of code in it. It should create object instances and use those to kick off the program.
 
mitchell cooper
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, ok when it come to moving the main how would i do it? where would i put it and how would i link it ?
 
Carey Brown
Saloon Keeper
Posts: 10834
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a basic template:


For the time being put all your code in the same directory. Then you can go to that directory and do a "javac *.java". That will link everything together.
 
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic