簡體   English   中英

如何將 combobox 添加到我的布局中? (爪哇)

[英]How do I add combobox to my layout? (java)

我在 java 中編寫了這個簡單的布局。 但它在第 36 行和第 37 行給了我一個錯誤,在那里我實現了 combobox。 我不明白為什么它不起作用。 它說

找不到符號符號:class ComboBox

這是完整的代碼

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

   }

}

在 Java AWT 中,選擇組件提供了您正在尋找的 function。 如果您正在制作 Swing GUI,那么您會想要使用JComboBox

它應該是JComboBox而不是 ComboBox。

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

當您使用 swing 時,請使用 JTextField、JLable、JButton 而不是 TextField、Label、Button。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM