• 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
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Event Handling

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator

I hope it helps


sure. thanks.
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic