2013-09-30 53 views
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.   
} 
+0

请发布整个示例 – Spiff

+1

请发布一个合理且可运行的示例。请更正您的问题中的英文和描述,因为它不易理解。 –

+0

您需要能够将标签添加到... – MadProgrammer

回答

0

假设Interface类是JFrame一个子类(我认为这是你在意味着JFrame中(第一类,命名接口)显示),只需调用add方法:

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

要有一个很好的布局,您可以使用LayoutManager之一。