Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何创建JButton的数组_Java_Arrays_Swing_Jbutton - Fatal编程技术网

Java 如何创建JButton的数组

Java 如何创建JButton的数组,java,arrays,swing,jbutton,Java,Arrays,Swing,Jbutton,我有个问题。我想创建一个类型为 private JButton[] butte; butte[3] = button; 触发这样的代码以失败告终 所有代码 public void LoadAllConfigureToCard(JPanel map) { Component[] component = map.getComponents(); for(int i=0; i<component.length; i++) {

我有个问题。我想创建一个类型为

private JButton[] butte;
butte[3] = button;
触发这样的代码以失败告终

所有代码

public void LoadAllConfigureToCard(JPanel map)
    {
        Component[] component = map.getComponents();
        for(int i=0; i<component.length; i++)
        {
            if (component[i] instanceof JButton)
            {
                final JButton button = (JButton)component[i];
                button.addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseDragged(MouseEvent arg0) {
                if(nocarddrag)
                {
                    Rectangle butt = button.getBounds();
                    int w = butt.width;
                    int h = butt.height;
                    PointerInfo a = MouseInfo.getPointerInfo();
                    Point pt = a.getLocation();
                    Rectangle movc = new Rectangle(pt.x, pt.y, w, h);
                    button.setBounds(movc);
                    cardisdrag = true;

                    butte[3] = button;
                }
                }

                });

            }
        }

    }
我应该怎么做才能在int类型的数组中指定前缀?

试试看

JButton[] btnArray = new JButton[10];
btnArray[3] = someButton;

您忘记创建对象。

您需要首先初始化数组:

private JButton[] butte = new JButton[100]; // or any other size you may want

你的问题应该是:如何创建数组?为了将来的参考,你应该发布错误消息,而不是仅仅说它以失败告终。我知道新程序员经常认为错误消息是不可理解的,但它们对于有经验的程序员来说是一个非常有用的信息来源——那些你想帮助你的信息。我有ButT[整数。PARSETIN ButoNo.C.GETNAME] =按钮;就这样结束了