• 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

Event Handling

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I wrote 2 classes:
mainframe.java and submitactionlistener.java.
The mainframe class implements a frame and contains some swing components, including a submit button.
If the button is clicked, a method should run, getting values from a JComboBox and a JTextField and save this stuff in the database.
But I don't know how to handle this.
The ActionListener works fine, but I couldn't find a way reading out the values and safe them ...
any help?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe, you may try declaring your components as private static. And implementing some getter and setter.
e.g:

This way, you may get and set your JTextField whenever you want in your SubmitActionListener, simply like this

I hope it was what you wanted
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oups, sorry, I didn't see that you wanted to save it in a database. For this, you should open a connection to your database.
Create a query with the values that you retrieved from the JTextField and then execute the query.
For that you should make a quick search in the jdbc forum
I hope it helps
 
leliel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I hope it helps


sure. thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic