2011-05-04 66 views
0

我在java中編寫了這個簡單的佈局。但它給我一個錯誤,在我執行組合框的行37。我不明白爲什麼它不起作用。它說如何將組合框添加到我的佈局? (java)

找不到符號符號:類 組合框

下面是完整的代碼

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 

    } 

} 

回答

0

應該JComboBox不是組合框。

JComboBox cboVehicle = new JComboBox(); 
JComboBox cboHookUps = new JComboBox(); 

當您使用擺動使用的JTextField,JLable,JButton的,而不是文本字段,標籤,按鈕。

+0

如果他一直在AWT上(因爲它看起來,覆蓋了油漆;) – kleopatra 2011-05-04 11:21:12

+0

@Kleopatra:是它看起來OP是使用awt,但他也有導入javax.swing。*所以我建議他,如果他想從awt轉移到swing。 – 2011-05-04 11:26:01

3

在Java AWT中,Choice組件提供了您正在查找的功能。如果你正在製作一個Swing GUI,那麼你會想要使用JComboBox

+0

這就是我正在尋找的東西。謝謝! – 2011-05-04 04:56:55

+0

現在它告訴我它無法找到構造函數 – 2011-05-04 05:03:36

+0

@Josh,因爲'Choice'沒有一個構造函數,它接受'int'參數來聲明它支持多少列(如TextField)。對於'Choice',只提供默認的構造函數'new Choice()'。 – 2011-05-04 05:10:00