0

这是按钮动作监听器的代码,当我按下这个按钮后,将设置 GridLayout 大小,并在里面添加文本字段,但是当我尝试将鼠标事件添加到文本中时会出现问题(我想要的功能是当我按 proID[0],然后 proName[0] 将设置文本为“0”和 proID[1],然后 proName[1] 将设置文本为“1”,然后全部)

static int k = 1;
static int i = 1;
static int countttt = 0;
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
    JTextField proID[] = new JTextField[i];
    JTextField proName[] = new JTextField[i];
    JTextField pUnitPrice[] = new JTextField[i];
    JTextField Qty[] = new JTextField[i];
    JTextField Linetotal[] = new JTextField[i];


    GridLayout experimentLayout = new GridLayout(k, 5, 1, 1);
    jPanel6.setLayout(experimentLayout);
    proID[countttt] = new JTextField("a" + countttt);
    proName[countttt] = new JTextField();
    pUnitPrice[countttt] = new JTextField();
    Qty[countttt] = new JTextField();
    Linetotal[countttt] = new JTextField();


    proID[countttt].addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            System.out.println(countttt);
            proName[countttt].setText(countttt);
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }
    });

    jPanel6.add(proID[countttt]);
    jPanel6.add(proName[countttt]);
    jPanel6.add(pUnitPrice[countttt]);
    jPanel6.add(Qty[countttt]);
    jPanel6.add(Linetotal[countttt]);
    i++;
    countttt++;
    k++;
    jPanel6.repaint();
    jPanel6.revalidate();


}
4

0 回答 0