Java JComboBox只能使用一次,并且不是';t更新

Java JComboBox只能使用一次,并且不是';t更新,java,swing,jcombobox,Java,Swing,Jcombobox,下面是我的代码,我已经尝试了每一件事。我尝试添加getSelectedItem()等。所有这些都没有用,ComboBox只能使用一次,甚至不会更新。帮帮我,伙计们 import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.*; import javax.swing.*; public class MainClass extends JFrame implements ActionListe

下面是我的代码,我已经尝试了每一件事。我尝试添加getSelectedItem()等。所有这些都没有用,ComboBox只能使用一次,甚至不会更新。帮帮我,伙计们

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.*;


public class MainClass extends JFrame implements ActionListener {
    String[] AmtOfPpl = {"1", "2", "3", "4"};

    private JLabel jlabel = new JLabel("Please select a table:");
    private JButton a01 = new JButton("A01");
    private JButton a02 = new JButton("A02");
    private JButton a03 = new JButton("A03");
    private JButton a04 = new JButton("A04");
    private JButton a05 = new JButton("A05");
    private JButton a06 = new JButton("A06");
    private JButton a07 = new JButton("A07");
    private JButton a08 = new JButton("A08");
    private JButton a09 = new JButton("A09");
    private JButton a10 = new JButton("A10");

    private JButton c01 = new JButton("C01");
    private JButton c02 = new JButton("C02");
    private JButton c03 = new JButton("C03");
    private JButton c04 = new JButton("C04");
    private JButton c05 = new JButton("C05");
    private JButton c06 = new JButton("C06");
    private JButton c07 = new JButton("C07");
    private JButton c08 = new JButton("C08");
    private JButton c09 = new JButton("C09");
    private JButton c10 = new JButton("C10");
    private JButton c11 = new JButton("C11");
    private JButton c12 = new JButton("C12");

    private JLabel FstName = new JLabel("*First Name: ");
    private JLabel LstName = new JLabel("*Last Name: ");
    private JLabel Addrss = new JLabel("Address: ");
    private JLabel PstlCode = new JLabel("Postal Code: ");
    private JLabel HndPne = new JLabel("*Handphone No.: ");
    private JLabel AoP = new JLabel("*Amount of People: ");
    private JLabel Mndtry = new JLabel("Fields marked with * are mandatory.");
    private JTextField FName = new JTextField();
    private JTextField LName = new JTextField();
    private JTextField Addr = new JTextField();
    private JTextField PCode = new JTextField();
    private JTextField HP = new JTextField();
    private JComboBox<?> AmtPpl = new JComboBox<Object>(AmtOfPpl);


    public MainClass() {

        JPanel p1 = new JPanel();
        p1.setLayout(new GridLayout(2,5,10,25));
        p1.add(a01);
        p1.add(a02);
        p1.add(a03);
        p1.add(a04);
        p1.add(a05);
        p1.add(a10);
        p1.add(a09);
        p1.add(a08);
        p1.add(a07);
        p1.add(a06);

        JPanel p2 = new JPanel();
        p2.setLayout(new GridLayout(6,2,2,2));
        p2.add(c01);
        p2.add(c02);
        p2.add(c03);
        p2.add(c04);
        p2.add(c05);
        p2.add(c06);
        p2.add(c07);
        p2.add(c08);
        p2.add(c09);
        p2.add(c10);
        p2.add(c11);
        p2.add(c12);

        a01.addActionListener(this);
        a02.addActionListener(this);
        a03.addActionListener(this);
        a04.addActionListener(this);
        a05.addActionListener(this);
        a06.addActionListener(this);
        a07.addActionListener(this);
        a08.addActionListener(this);
        a09.addActionListener(this);
        a10.addActionListener(this);

        c01.addActionListener(this);
        c02.addActionListener(this);
        c03.addActionListener(this);
        c04.addActionListener(this);
        c05.addActionListener(this);
        c06.addActionListener(this);
        c07.addActionListener(this);
        c08.addActionListener(this);
        c09.addActionListener(this);
        c10.addActionListener(this);
        c11.addActionListener(this);
        c12.addActionListener(this);

        AmtPpl.setSelectedIndex(3);
        AmtPpl.addActionListener(this);

        setLayout(new BorderLayout(20,10));
        add(jlabel, BorderLayout.NORTH);
        add(p1, BorderLayout.CENTER);
        add(p2, BorderLayout.EAST);


    }

    public static void main(String[] args) {
        MainClass frame = new MainClass();
        frame.setTitle("Table Reservation System");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(550, 300);
        frame.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {

        JPanel InputPanel = new JPanel();
        InputPanel.setLayout(new GridLayout(7,2));
        InputPanel.add(FstName);
        InputPanel.add(FName);
        InputPanel.add(LstName);
        InputPanel.add(LName);
        InputPanel.add(Addrss);
        InputPanel.add(Addr);
        InputPanel.add(PstlCode);
        InputPanel.add(PCode);
        InputPanel.add(HndPne);
        InputPanel.add(HP);
        InputPanel.add(AoP);
        InputPanel.add(AmtPpl);
        InputPanel.add(Mndtry);

        if(e.getSource()==a01) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a02) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a03) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a04) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a05) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a06) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a07) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a08) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a09) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==a10) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c01) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c02) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c03) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c04) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c05) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c06) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c07) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c08) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c09) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c10) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c11) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
        else if(e.getSource()==c12) {
            JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
        }
    }
}
导入java.awt.BorderLayout;
导入java.awt.GridLayout;
导入java.awt.event.*;
导入javax.swing.*;
公共类MainClass扩展JFrame实现ActionListener{
字符串[]AmtOfPpl={“1”、“2”、“3”、“4”};
private JLabel JLabel=new JLabel(“请选择一个表:”);
私有JButton a01=新JButton(“a01”);
私有JButton a02=新JButton(“a02”);
私有JButton a03=新JButton(“a03”);
私有JButton a04=新JButton(“a04”);
专用JButton a05=新JButton(“a05”);
专用JButton a06=新JButton(“a06”);
私有JButton a07=新JButton(“a07”);
私有JButton a08=新JButton(“a08”);
私有JButton a09=新JButton(“a09”);
私有JButton a10=新JButton(“a10”);
私有JButton c01=新JButton(“c01”);
私有JButton c02=新JButton(“c02”);
私有JButton c03=新JButton(“c03”);
私有JButton c04=新JButton(“c04”);
私有JButton c05=新JButton(“c05”);
私有JButton c06=新JButton(“c06”);
私有JButton c07=新JButton(“c07”);
私有JButton c08=新JButton(“c08”);
私有JButton c09=新JButton(“c09”);
私有JButton c10=新JButton(“c10”);
私有JButton c11=新JButton(“c11”);
私有JButton c12=新JButton(“c12”);
private JLabel FstName=新JLabel(“*名字:”);
私有JLabel LstName=新JLabel(“*姓氏:”);
私有JLabel Addrss=新JLabel(“地址:”);
私有JLabel PstlCode=新JLabel(“邮政编码:”);
私人JLabel HndPne=新JLabel(“*手机号码:”);
private JLabel AoP=新JLabel(“*人数:”);
private JLabel Mndtry=new JLabel(“带有*标记的字段是必需的”);
私有JTextField FName=新JTextField();
私有JTextField LName=新JTextField();
私有JTextField Addr=新JTextField();
私有JTextField PCode=新JTextField();
私有JTextField HP=new JTextField();
私有jcombox AmtPpl=新jcombox(amtofpl);
公共类(){
JPanel p1=新的JPanel();
p1.设置布局(新网格布局(2,5,10,25));
p1.添加(a01);
p1.添加(a02);
p1.添加(a03);
p1.添加(a04);
p1.添加(a05);
p1.添加(a10);
p1.添加(a09);
p1.添加(a08);
p1.添加(a07);
p1.添加(a06);
JPanel p2=新的JPanel();
p2.设置布局(新网格布局(6,2,2,2));
p2.添加(c01);
p2.添加(c02);
p2.添加(c03);
p2.添加(c04);
p2.添加(c05);
p2.添加(c06);
p2.添加(c07);
p2.添加(c08);
p2.添加(c09);
p2.添加(c10);
p2.添加(c11);
p2.添加(c12);
a01.addActionListener(本);
a02.addActionListener(本);
a03.addActionListener(本);
a04.addActionListener(本);
a05.添加ActionListener(本);
a06.addActionListener(本);
a07.addActionListener(本);
a08.addActionListener(本);
a09.addActionListener(本);
a10.添加ActionListener(本);
c01.addActionListener(本);
c02.addActionListener(本);
c03.addActionListener(本);
c04.addActionListener(本);
c05.addActionListener(本);
c06.addActionListener(本);
c07.addActionListener(本);
c08.addActionListener(本);
c09.addActionListener(本);
c10.addActionListener(此);
c11.addActionListener(本);
c12.addActionListener(本);
AmtPpl.setSelectedIndex(3);
AmtPpl.addActionListener(此);
setLayout(新边界布局(20,10));
添加(jlabel,BorderLayout.NORTH);
添加(p1,BorderLayout.CENTER);
添加(p2,边界布局。东部);
}
公共静态void main(字符串[]args){
MainClass框架=新的MainClass();
frame.setTitle(“表格预订系统”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
框架设置尺寸(550300);
frame.setVisible(true);
}
已执行的公共无效操作(操作事件e){
JPanel InputPanel=新的JPanel();
设置布局(新的网格布局(7,2));
InputPanel.add(FstName);
InputPanel.add(FName);
InputPanel.add(LstName);
InputPanel.add(LName);
InputPanel.add(Addrss);
InputPanel.add(Addr);
InputPanel.add(PstlCode);
InputPanel.add(PCode);
InputPanel.add(HndPne);
InputPanel.add(HP);
InputPanel.add(AoP);
InputPanel.add(AmtPpl);
InputPanel.add(Mndtry);
如果(如getSource()==a01){
showConfirmDialog(null,InputPanel,“请输入所需信息”,JOptionPane.OK\u CANCEL\u选项);
}
else if(e.getSource()==a02){
showConfirmDialog(null,InputPanel,“请输入所需信息”,JOptionPane.OK\u CANCEL\u选项);
}
else if(e.getSource()==a03){
showConfirmDialog(null,InputPanel,“请输入所需信息”,JOptionPane.OK\u CANCEL\u选项);
}
else if(e.getSource()==a04){
showConfirmDialog(null,InputPanel,“请输入所需信息”,JOptionPane.OK\u CANCEL\u选项);
}
else if(e.getSource()==a05){
showConfirmDialog(null,InputPanel,“请输入所需信息”,JOptionPane.OK\u CANCEL\u选项);
}
else if(e.getSource()==a06){
showConfirmDialog(null,InputPanel,“请输入所需信息”,JOptionPane.OK\u CANCEL\u选项);
}
else if(e.getSource()==a07){
showConfirmDialog(null,InputPanel,“请输入
    if(e.getSource()==a01) {
        JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);
    }
 private void showOptionPane() {
   JPanel InputPanel = new JPanel();
    InputPanel.setLayout(new GridLayout(7,2));
    InputPanel.add(FstName);
    InputPanel.add(FName);
    InputPanel.add(LstName);
    InputPanel.add(LName);
    InputPanel.add(Addrss);
    InputPanel.add(Addr);
    InputPanel.add(PstlCode);
    InputPanel.add(PCode);
    InputPanel.add(HndPne);
    InputPanel.add(HP);
    InputPanel.add(AoP);
    InputPanel.add(AmtPpl);
    InputPanel.add(Mndtry); 

    JOptionPane.showConfirmDialog(null, InputPanel, "Please enter the required information", JOptionPane.OK_CANCEL_OPTION);


}
AmtPpl.addActionListener(this);