• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 74376
334
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic