执行的JAVA操作不起作用

执行的JAVA操作不起作用,java,swing,jframe,jbutton,buttonclick,Java,Swing,Jframe,Jbutton,Buttonclick,我正在为此创建按钮,当我单击他的时候。。没有发生任何事。。。当我点击btn时,没有调用函数btnActionPerformed。。。如何让它工作 private void btButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here int[] ret = new

我正在为此创建按钮,当我单击他的时候。。没有发生任何事。。。当我点击btn时,没有调用函数btnActionPerformed。。。如何让它工作

private void btButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                              
    // TODO add your handling code here
    int[] ret = new int[SQL.freetables().size()];
    Iterator<Integer> iterator = SQL.freetables().iterator();
    for (int i = 0; i < ret.length; i++)
    {
    ret[i] = iterator.next().intValue();
    int num=SQL.freetables().size() + 1;
    this.btn = new JButton();
    this.btn.setText("" + ret[i]);
    this.btn.setSize(60,20);
    int x = 100+(80*i);
    this.btn.setLocation(x, 140);
    this.btn.setVisible(true);
    this.add(btn);     
   // }

    }
    this.revalidate();
    this.repaint();
}          

private void btnActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    System.out.print("\b Test: " + btn.getText());
} 
private void btButton1ActionPerformed(java.awt.event.ActionEvent evt){
//TODO在此处添加您的处理代码
int[]ret=new int[SQL.freetables().size()];
迭代器迭代器=SQL.freetables().Iterator();
对于(int i=0;i
您必须实现
ActionListener
接口。这两种方法都与我看到的所需签名不匹配

该方法是
actionPerformed
。监听器必须连接到
JButton
。我在你的代码中都没有看到


你似乎非常需要一份工作

您必须实现
ActionListener
接口。这两种方法都与我看到的所需签名不匹配

该方法是
actionPerformed
。监听器必须连接到
JButton
。我在你的代码中都没有看到


你似乎非常需要一份工作

您需要注册到
actionPreformed

this.btn.addActionListener(this);
您的代码应该是:

bt.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
       // TODO add your handling code here
       int[] ret = new int[SQL.freetables().size()];
       Iterator<Integer> iterator = SQL.freetables().iterator();
       for (int i = 0; i < ret.length; i++)
       {
          ret[i] = iterator.next().intValue();
          int num=SQL.freetables().size() + 1;
          this.btn = new JButton();
          this.btn.setText("" + ret[i]);
          this.btn.setSize(60,20);
          int x = 100+(80*i);
          this.btn.setLocation(x, 140);
          this.btn.setVisible(true);
          this.add(btn);   
          btn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent ae) { 
               // TODO add your handling code here:
               System.out.print("\b Test: " + btn.getText());
             } 
          }

          this.revalidate();
          this.repaint();
       }
    }
});
bt.addActionListener(新ActionListener(){
已执行的公共无效行动(行动事件ae){
//TODO在此处添加您的处理代码
int[]ret=新建int[SQL.freetables().size()];
迭代器迭代器=SQL.freetables().Iterator();
对于(int i=0;i
您需要注册到
actionPreformed

this.btn.addActionListener(this);
您的代码应该是:

bt.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
       // TODO add your handling code here
       int[] ret = new int[SQL.freetables().size()];
       Iterator<Integer> iterator = SQL.freetables().iterator();
       for (int i = 0; i < ret.length; i++)
       {
          ret[i] = iterator.next().intValue();
          int num=SQL.freetables().size() + 1;
          this.btn = new JButton();
          this.btn.setText("" + ret[i]);
          this.btn.setSize(60,20);
          int x = 100+(80*i);
          this.btn.setLocation(x, 140);
          this.btn.setVisible(true);
          this.add(btn);   
          btn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent ae) { 
               // TODO add your handling code here:
               System.out.print("\b Test: " + btn.getText());
             } 
          }

          this.revalidate();
          this.repaint();
       }
    }
});
bt.addActionListener(新ActionListener(){
已执行的公共无效行动(行动事件ae){
//TODO在此处添加您的处理代码
int[]ret=new int[SQL.freetables().size()];
迭代器迭代器=SQL.freetables().Iterator();
对于(int i=0;i
It work…:)…但我还有一个问题,如果我把执行的操作放在for中,当我得到btn的文本时,是否会有最后一个空闲表数…如果我得到两个空闲表,单击时是1和3,每次我都会得到“3”…所以,这就是我试图跳出for循环的原因…它起作用了…)。。但我还有一个问题,如果我把执行的操作放在for中,当我得到btn的文本时,最后一个空闲表的数目会不会。。。如果我有两张免费的桌子,当我点击时是1和3,每次我都会得到“3”。。。所以,这就是我试图跳出for循环的原因…嗯。。。谢谢你,我将看到这个教程来学习更多的swing。。。我在Android上工作,所以我不需要swing样式,但现在我确信布局样式是不同的。。我会读到关于swing…嗯。。。谢谢你,我将看到这个教程来学习更多的swing。。。我在Android上工作,所以我不需要swing样式,但现在我确信布局样式是不同的。。并将阅读有关swing。。。