I wrote this simple layout in java. But It's giving me an error on line 36 & 37 where I implemented the combobox. I don't see why it's not working. It Says
cannot find symbol symbol : class ComboBox
Here is the complete code
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class DropDownApplet extends Applet implements ActionListener {
//define variables, Button, label, TextField
//Create a Button class
Button btnSubmit = new Button("Submit");
Button btnClear = new Button("Clear");
Label lblFname = new Label("First Name");
Label lblLname = new Label("Last Name");
Label lblAddress = new开发者_开发知识库 Label("Address");
Label lblCity = new Label("City");
Label lblState = new Label("State");
Label lblVehicle = new Label("Select Vehicle Type");
Label lblHookups = new Label("Select Hookups");
Label lblArrival = new Label("Arrival Date");
Label lblNights = new Label("Number of Nights");
Label lblZip = new Label("Zip");
TextField txtFname = new TextField(10);
TextField txtLname = new TextField(10);
TextField txtAddress = new TextField(10);
TextField txtCity = new TextField(10);
TextField txtState = new TextField(10);
ComboBox cboVehicle = new ComboBox(10);
ComboBox cboHookUps = new ComboBox(10);
TextField txtArrival = new TextField(10);
TextField txtNights = new TextField(10);
TextField txtZips = new TextField(10);
public void init() {
// add the displayable objects;
setBackground(Color.red);
add(lblFname);
add(txtFname);
txtFname.requestFocus();
add(lblLname);
add(txtLname);
add(lblAddress);
add(txtAddress);
add(lblCity);
add(txtCity);
add(lblState);
add(txtState);
add(lblVehicle);
add(cboVehicle);
add(lblHookups);
add(cboHookups);
add(lblArrival);
add(txtArrival);
add(lblNights);
add(txtNights);
add(lblZip);
add(txtZips);
add(btnSubmit);
add(btnClear);
//Attach event to Button
btnSubmit.addActionListener(this);
btnClear.addActionListener(this);
}
public void paint(Graphics g) {
//Draw any pictures
//Make sure the picture is in the same directory as the .class files
}
public void actionPerformed(ActionEvent e) {
//This method will fire when button is pressed
//define temporary variables
}
}
In Java AWT, the Choice Component provides the function you are looking for. If you were making a Swing GUI then you would want to use JComboBox.
It should be JComboBox not ComboBox.
JComboBox cboVehicle = new JComboBox();
JComboBox cboHookUps = new JComboBox();
And when you are using swing use JTextField, JLable, JButton instead of TextField, Label, Button.
精彩评论