0

関数を呼び出すときに、ラベルを作成しようとしています。しかし、私はこれを行うことはできません..どのようにそれを行うには? funcoes.test()メソッド (最初のコードの下)を介してラベルを作成し、 JFrame(最初のクラス、名前付きInterface)に表示したい

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:,
    System.out.print("test");
    for(int i = 1; i < 5; i++) {
        System.out.print("hi");
        this.button = new JButton();
        this.button.setSize(60, 50);
        this.button.setLocation(50+(80*i), 100);
        this.button.setVisible(true);
        this.button.setText("" + i);
        this.button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                int op = Integer.parseInt(ae.getActionCommand());
                funcoes.test(op);

            }  
        });
        this.add(button);
        this.jPanel1.add(button);
        this.revalidate();
        this.repaint();


    }
}

これが私の他のクラスです:

public class funcoes extends Interface {
    public static void test(int x) {
        System.out.print("Hi: " + x);
        JLabel numero = new JLabel();
        JLabel total = new JLabel();
        //Interface.        
}
4

1 に答える 1

0

Interfaceクラスがのサブクラスであると仮定すると(これがJFrame (最初のクラス、Interface という名前) で表示JFrameするという意味だと思います)、add メソッドを呼び出すだけです。

JLabel numero = new JLabel();
JLabel total = new JLabel();
add(numero);
add(total);

良いレイアウトにするために、LayoutManagerのいずれかを使用できます。

于 2013-09-30T19:21:36.367 に答える