• 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

Getting my Choice to reset when I use my "clear" button

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class DavidApplet extends Applet implements ActionListener
{
//Declaring Variables
String firstName;
String lastName;
String address;
String city;
String state;
String zip;
String arrivalDate;
int numberNights;
//Create components for the applet
Label firstNameLabel = new Label("First Name:");
TextField firstNameField = new TextField(15);
Label lastNameLabel = new Label("LastName:");
TextField lastNameField = new TextField(15);
Label addressLabel = new Label("Address:");
TextField addressField = new TextField(15);
Label cityLabel = new Label(" City:");
TextField cityField = new TextField(15);
Label stateLabel = new Label(" State:");
TextField stateField = new TextField(15);

Label zipLabel = new Label("Zip:");
TextField zipField = new TextField(15);
Label campingVehiclesLabel = new Label(" ");
Choice campingVehiclesChoice = new Choice();
Label hookUpLabel = new Label(" ");
Choice hookUpChoice = new Choice();
Label arrivalDateLabel = new Label(" Arrival Date");
TextField arrivalDateField = new TextField(15);
Label numberNightsLabel = new Label(" Number of Nights");
TextField numberNightsField = new TextField(15);
Button submitButton = new Button("Submit ");
Button clearButton = new Button("Clear");

public void init()
{
//Add components to window and set colors
setBackground(Color.orange);
add(firstNameLabel);
add(firstNameField);
firstNameField.requestFocus();
add(lastNameLabel);
add(lastNameField);
add(addressLabel);
add(addressField);
add(cityLabel);
add(cityField);
add(stateLabel);
add(stateField);
add(zipLabel);
add(zipField);
add(campingVehiclesLabel);
add(campingVehiclesChoice);
campingVehiclesChoice.addItem("Camping Vehicles");
campingVehiclesChoice.addItem("Tent ");
campingVehiclesChoice.addItem("Pop-up ");
campingVehiclesChoice.addItem("Travel Trailer ");
campingVehiclesChoice.addItem("Fifth-Wheel ");
campingVehiclesChoice.addItem("Motor Home ");
add(hookUpLabel);
add(hookUpChoice);
hookUpChoice.addItem("Hook-ups ");
hookUpChoice.addItem("Water only ");
hookUpChoice.addItem("Water and Electricity");
hookUpChoice.addItem("Full Hook-ups ");
hookUpChoice.addItem("No Hook-up ");
add(numberNightsLabel);
add(numberNightsField);
add(arrivalDateLabel);
add(arrivalDateField);
add(submitButton);
submitButton.addActionListener(this);
add(clearButton);
clearButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if (arg == "Submit")
{
//Assigning data
firstName = firstNameField.getText();
lastName = lastNameField.getText();
address = addressField.getText();
city = cityField.getText();
state = stateField.getText();
zip = zipField.getText();
arrivalDate = arrivalDateField.getText();
numberNights = Integer.parseInt(numberNightsField.getText());

}
if (arg == "Clear")
{
firstNameField.setText("");
lastNameField.setText("");
addressField.setText("");
cityField.setText("");
stateField.setText("");
zipField.setText("");
arrivalDateField.setText("");
numberNightsField.setText("");
repaint();
}
}
}
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
firewolfe32,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
----------------------
Also, please note that you can preserve code formatting by surrounding it with the [code] and [/code] UBB Tags. You also have the ability to edit your own posts. Just click on the icon that looks like a piece of paper.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The clear button seems to erase stuff. What's the problem?
 
reply
    Bookmark Topic Watch Topic
  • New Topic