• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

creating a gui

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have a GUI class that has 2 text fields and a submit and reset button.
I have added all the listeners and would like to process this form if auser clicks on the submit button.However, if he clicks on the reset button, I want the form to clear.

What should I do so that when I click the submit button, I get the values of the two text fields and when I click the reset button, the form just resets.

Below are snippets of code for the rest of my Gui.


class NameL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
nameE = nameInput.getText();
}
}

class LocationL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
locChoices = (JComboBox)e.getSource();
locationE = (String)locChoices.getSelectedItem();
}
}

class ButtonL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String name = ((JButton)e.getSource()).getText();
if(name.equals("submit"))
System.out.println("create a vector with all the values you have got " + nameE + " and" + locationE);
else
System.out.println("you have pressed the reset button and must clear all the fields");
}
}
 
Marshal
Posts: 80943
521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean you want to set the text to "" if you push the "reset" button?
Do you want to enter the text from your text field and combo box into some application if you push the "submit" button?

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