• 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Design Help Requested  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody!  New guy here. Mainly Access VBA, SQL dude for many years.  52 year old Java Rookie.  Just recently finished my Java book and am starting to do some coding.  I'm working on a test project in which i can click on some buttons, and fool around.  I want something in which a list of information displays.  I want to be able to click on one of these rows of information and be able to access a bit of information to do something with it.  The list will be a list of my pets names along with their ages.  About 50 or so pets.  I want the names to be visible but the ages should not be visible.  If I clicked on my dog's name "Rover", I can then get his age of 10 and apply some math to it for example.  This list will be hard coded, I don't want to use a relational database at the moment.  I want to use some kind of java built-in data structure.    I'm asking for a little guidance on what Swing container/component data structure combination to use to accomplish this.  Just want to start on a good component / data structure combination that you all feel is most natural for this.  Or at least a good candidate.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use Java Swing GUI and  List  Set Map
 
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Juancito, welcome to the Ranch!

From your description it sounds like you need a JTable. You can find a tutorial about JTable here: How to Use Tables.

However since you're a Java novice as well as a Swing novice you could well benefit from working through the whole Swing tutorial: Lesson: Using Swing Components. There's a lot of information there and JTable is down near the bottom.

Or you could just jump straight into the tar pit and yell for help when you get stuck...
 
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JH: please post something useful.

OP: welcome to the Ranch
Don't write a GUI at this point. Write an application that will record your ages and print them on the terminal/command line. Before you can work out what sort of data structure to use, I think yoiu should explain to us (and more to yourself) how you want those data to be organised. Of course, the object‑oriented way is to create a Pet class with fields like name and age.
Once you have all that lot working, then consider how to write the GUI.
 
Juancito Matos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone.
 
Ranch Hand
Posts: 380
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all you have 50 pets?!  
If you don't want to use a database, which you don't really need if the data isn't going to be changing, then you could put the info in a file.  You would get the data from the file when you start the program.  Hard-coding the data would be a real pain especially if you want to make changes.
 
Juancito Matos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nah, don't have 50 pets. I should have added "...true story...". This reply of mine is a cell phone reply test, at a bar. Let's see how it goes. i have a button that causes a message box to display, a button that changes the caption on a label, a button that writes the contents of  a Jtextfield to a file. Now I'm adding buttons to enforce my new knowledge of array lists, hash maps and string object arrays or something like that. This app is a testing app that reinforces stuff i read about. It's okay to not be professional or of good design.
 
Juancito Matos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Juancito Matos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afraid that isn't the right way to write an application. Write the application first and add the GUI later. What you have achieved is a class which is a mess. You have tried to put everything into one method, and that block of if‑elses is a really difficult thing to maintain.
You also have incorrect use of CapitalLetters in methods. Don't start method names with CapitalLetters.
 
Juancito Matos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dont think of it as an application. and definitely don't think of it as an application to be maintained. in my original post i said it was a test project in which i was fooling around. i supplied the code to help make it clearer this is test bed of the simplest ideas that the more experienced programmers take for granted, like dealing with labels for example.
 
Campbell Ritchie
Marshal
Posts: 64172
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Juancito Matos wrote:dont think of it as an application. . . . .

But it looks to me like you getting in to bad habits early in your career, which had habits will take no end of effort to break, and which if presented to a potential employer will ensure you don't get the job.
 
Juancito Matos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who said anything about me being early in my career?  I'm closer to retiring than when I first got into this type of work.  And I plan to retire at the great company i work for which is not a Java shop.  I started learning Java about a month ago for a few reasons. 1. it came with the Raspian image on my pi, so why not? 2. I want to try my hand at an Android project, just for fun, not for employment and not to sell android apps.  and 3. Just thought it would be interesting to pick up a new hobby.  The pi is a new hobby in itself.  And who said I have bad habits?  this is just a stupid test project to test out a few things.  One of the excellent habits I have and which I hope all have is to be consistent in coding style. What i do works for me and has served me well.

But the naming conventions recommendations are appreciated.  I'll try to incorporate that into my coding in case I post code in the future, so that folks have an easier time reading it, in case it's so hard to follow otherwise.



RaspberryPi.jpg
[Thumbnail for RaspberryPi.jpg]
 
Bartender
Posts: 2230
94
Eclipse IDE Google Web Toolkit Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Op, welcome to code ranch. It is our duty to point out bad code when we see it. You gui may do wonders, but if it's internally a mess, you're inevitably doomed. Bad code always comes back to haunt you. Or even worse, it would haunt the next person trying to work on your code.

For a good java programmer, a user interface is simply a "shell" or an outer layer of sorts. The 'core' code should allow you to do precisely what the problem states: Fetch a list of information, Fetch "Rover's" info, Do some age math, etc... without a UI.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!