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.
}
请发布整个示例 – Spiff
请发布一个合理且可运行的示例。请更正您的问题中的英文和描述,因为它不易理解。 –
您需要能够将标签添加到... – MadProgrammer