File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Getting my Choice to reset when I use my Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting my Choice to reset when I use my "clear" button" Watch "Getting my Choice to reset when I use my "clear" button" New topic
Author

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

joey_g30
Greenhorn

Joined: Aug 29, 2002
Posts: 4
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

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
The clear button seems to erase stuff. What's the problem?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting my Choice to reset when I use my "clear" button
 
Similar Threads
method not abstract
. . .not abstract and doesnt overide abstract method actionPerfomed
Layout clarification
writeUTF and JComboBox
Applet Code Error