gpt4 book ai didi

java - JComboBox[] 循环在 JApplet 上显示不起作用

转载 作者:行者123 更新时间:2023-12-01 13:01:46 24 4
gpt4 key购买 nike

public class NewAccountApplet extends JApplet implements ActionListener{
JPanel jp1, jp2, jp3, jp4, jp5, jp6;
GridLayout productLO = new GridLayout(10,4,10,10);
int qty = 5;
JComboBox<Object>[] selectQty;

if (e.getActionCommand().equals("Login")) {

if (id.equals(checkID) && pw.equals(checkPW)) {
JOptionPane.showMessageDialog(null, "Authenticated");
JPanel content = (JPanel)getContentPane();
GridBagConstraints firstCol = new GridBagConstraints();
firstCol.weightx = 1.0;
firstCol.anchor = GridBagConstraints.WEST;
firstCol.insets = new Insets(5, 20, 5, 5);
GridBagConstraints lastCol = new GridBagConstraints();
lastCol.gridwidth = GridBagConstraints.REMAINDER;
lastCol.weightx = 1.0;
lastCol.fill = GridBagConstraints.HORIZONTAL;
lastCol.insets = new Insets(5, 5, 5, 20);

selectQty = new JComboBox[qty];

jp1.setVisible(false);
jp2.setVisible(false);
jp3.setVisible(false);
jp4.setVisible(true);
jp5.setVisible(true);
jp6.setVisible(true);

String[] itemText = {"1", "2", "3", "4", "5"};
JLabel[] items = new JLabel[6];
JLabel purchasePage = new JLabel("Items for Purchase");
jp4.add(purchasePage);
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
content.add(jp4);

jp4 = new JPanel();
jp5 = new JPanel(new GridBagLayout()); //set jp5 as a new jpanel with gridbaglayout
jp6 = new JPanel();

for(int i=0; (i<items.length); i++) {
items[i] = new JLabel(); //adds items[i] as JLabel
items[i].setText(itemText[i]); //sets text of items as itemText[]
jp5.add(items[i], firstCol); //adds items to firstcol of jp5
selectQty[i] = new JComboBox<Object>(); //JComboBox selectqty[i]
selectQty[i].setPreferredSize(new Dimension(300, 20)); //sets the size
jp5.add(selectQty[i], lastCol); //sadsdasd
}

}
else JOptionPane.showMessageDialog(null, "Wrong account information");}

我对将 JComboBox 添加到循环中以在我的 JApplet 上显示有一些疑问。底部的 for 循环将我的 JComboBox (selectQty) 添加到屏幕。但我在 Eclipse 上收到一条错误消息,其中我编码为:items[i].setText(itemText[i]);。它正确显示了我的 JPanel jp4。但 JPanel jp5 没有显示..我想知道出了什么问题...

总而言之,代码可以编译(以及此处未列出的其他代码),但 japplet 只显示 jp4 jpanel,并且在线出现错误:items[i].setText(itemText[i]);。

最佳答案

itemText 有 5 个元素 {"1", "2", "3", "4", "5"}JLabel[] items = new JLabel[6] 项目有 6 个。

关于java - JComboBox[] 循环在 JApplet 上显示不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23465618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com