Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Autogenerated ID

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am creating a GUI for cars. If I add a car I want to give that car an autogenerated ID, but I really do not now where to start... Does someone know an useful method for this?
 
Saloon Keeper
Posts: 7615
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want the GUI to remember the last ID number assigned between executions of the program? If so, then you are talking about "persistence". Databases have a way to remember and automatically increment an ID field in a table. If you don't need a database you could simply use a flat file that you constantly update and read.
 
Ellen Reddix
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for answering! I want to be able to write the name of the car in a field that I have created and then press a button with the text "get autogenerated carID" or something and the ID will pop up in another field. I want the computer to remember which Id that belongs to the car and be able to give a new ID to a new car etc.
 
Carey Brown
Saloon Keeper
Posts: 7615
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, are you going to use a database for this?
 
Ellen Reddix
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No! I am writing my code in a controller and running it with a main.java file!
 
Carey Brown
Saloon Keeper
Posts: 7615
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I guess you are going to be writing to a file then. Have you ever done that before?

In the mean time you'd want to have a class like a "Car" class with fields for "name" and "id".
 
Rancher
Posts: 4784
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your app need to remember the Cars between runs?

In other words, you run your app, add some cars, then shut it down.
When you come back the following day, start up the app, does it need to know the Cars created the day before?
 
Ellen Reddix
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No the program does not have to remember the cars between the runs.
Everything is done except the autogenerated ID. Right now you write it manually, but I want it to be generated when you write the name of the car.
 
Dave Tolls
Rancher
Posts: 4784
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so what does your Car class look like?
 
Master Rancher
Posts: 4083
37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does an ID look like? Is it a String or an int or what?
reply
    Bookmark Topic Watch Topic
  • New Topic