我怎样才能多个阵列添加到的JComboBox? [英] How can I add multiple arrays to a JComboBox?

查看:161
本文介绍了我怎样才能多个阵列添加到的JComboBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一些课程剧院座位预订系统,但我有创造的JComboBox帮助用户选择的一组197有完全的座位麻烦。

I am making a theatre seat bookings system for some coursework but am having trouble on creating a JComboBox to help the user select a seat from the set of 197 that there are altogether.

该席位再次按座位对象这仅仅是一些变量,如isBooked(布尔)的集合psented $ P $。座椅布置成多个座位阵列,每个阵列重新presents一排座位如A [],B [] ...

The seats are represented by "Seat" objects which are merely a collection of a few variables such as "isBooked" (Boolean). The seats are arranged into multiple seat arrays, each array represents a row of seats e.g. A[], B[]...

有关预订的座位,具有由行分隔座椅是必要的。

For the booking of the seats, having the seats separated by row was necessary as they have different prices, however the JComboBox will be used as a way of selecting a seat to unbook and hence just a full list of seats is required.

我可以在单个阵列轻松添加到JComboBox中和它的工作不错,但为了更多的阵列添加到列表中的JComboBox失败。

I can easily add a single array to the JComboBox and have it work fine but an attempt to add any more arrays to the list in the JComboBox fails.

我如何添加多个阵列的JComboBox中?
即,A [1],A [2],A [3] ... A [14],B [1],B [2] ...

How can I add multiple arrays to the JComboBox? i.e. A[1], A[2], A[3]... A[14], B[1], B[2]...

我不是非常有经验的在Java中很抱歉,如果这是一个愚蠢的问题。
经过大量的研究,在过去的几天里,我曾试图与DefaultComboBoxModel类实验,但我显然不正确地使用它。这是我最近来解决我的问题的尝试:

I am not very experienced in Java so sorry if this is a stupid question. After lots of research over the past few days, I have tried experimenting with the DefaultComboBoxModel class but am obviously not using it correctly. This was my most recent attempt to solve my problem:

DefaultComboBoxModel model = new DefaultComboBoxModel();
            model.addElement(A);
            model.addElement(B);
            model.addElement(C);
            model.addElement(D);
            model.addElement(E);
            model.addElement(F);
            model.addElement(G);
            model.addElement(H);
            model.addElement(J);
            model.addElement(K);
            model.addElement(L);
            JComboBox seatCombobox = new JComboBox();
            seatCombobox.setModel(model);
            unbookSeatWindow.buttonsPanel.add(seatCombobox);

所有帮助将AP preciated。

All help will be appreciated.

推荐答案

您DefaultComboBoxModel code是正确答案。你只是尽可能多的数组中添加元素为你。

Your DefaultComboBoxModel code is the correct answer. You just add elements from as many arrays as you have.

我建议您使用两个JComboBox组件。一个用于部分,和另一个用于座位号。否则,你的用户会感到沮丧,阅读上百个席位的名单。

May I suggest that you use two JComboBox components. One for the section, and another for the seat number. Otherwise, your users will get frustrated reading a list of hundreds of seats.

这篇关于我怎样才能多个阵列添加到的JComboBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆