Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
joey_g30
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • 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();
}
}
}
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The clear button seems to erase stuff. What's the problem?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic