Java 执行的void操作多次执行,不给出任何循环语句

Java 执行的void操作多次执行,不给出任何循环语句,java,arrays,Java,Arrays,每次调用actionPerformed(),它都会根据调用的次数执行 问题: 第一个调用对该调用执行一次 第二个调用方法在一行中执行两次(连续) 第三次调用-连续执行3次 如此类推…第n次调用-为该调用连续执行n次 对于每个调用,执行次数增加一次 我没有使用任何类型的循环,并且闭合大括号放置在正确的位置 这是我的密码: public class Opensbt extends SBT implements ActionListener { static String sele

每次调用
actionPerformed()
,它都会根据调用的次数执行

问题:

  • 第一个调用对该调用执行一次
  • 第二个调用方法在一行中执行两次(连续)
  • 第三次调用-连续执行3次
  • 如此类推…第n次调用-为该调用连续执行n次
对于每个调用,执行次数增加一次

我没有使用任何类型的循环,并且闭合大括号放置在正确的位置

这是我的密码:

   public class Opensbt extends SBT implements ActionListener {

    static String selected = "";
     int i = 0;
     int j = 0;

private static final long serialVersionUID = 1581264288151208369L;


 JButton Openbtn = new JButton("Open");
//@SuppressWarnings("deprecation")
 @Override
public void actionPerformed(ActionEvent e) {
     System.out.println("Second");

    AbstractBorder brdr = new TextBubbleBorder(Color.LIGHT_GRAY, 1, 8, 0);
    fileopen = new JInternalFrame("Open", true, true, false, false);
    fileopen.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    fileopen.setSize(200, 200);
    fileopen.setBorder(brdr);
    fileopen.setBounds(0, 2, 145, 30);

    desktop.add(fileopen);
    JPanel jp = new JPanel(new GridBagLayout());

    jp.setPreferredSize(new Dimension(300, 200));

    GridBagConstraints firstCol = new GridBagConstraints();
    firstCol.anchor = GridBagConstraints.WEST;
    GridBagConstraints lastCol = new GridBagConstraints();
    lastCol.gridwidth = GridBagConstraints.REMAINDER;
    lastCol.fill = GridBagConstraints.HORIZONTAL;

     List lb = new List(2);

    lb.setBackground(Color.white);
    l_label = new JLabel("<html><font size=3 , Arial color=black><b>"
            + "Open file :</b></font></html>");
    jp.add(l_label, firstCol);

    jp.add(l_label, firstCol);
    lastCol.gridwidth = GridBagConstraints.REMAINDER;

    lastCol.fill = GridBagConstraints.VERTICAL;
    jp.add(lb);
        Openbtn.setMargin(new java.awt.Insets(1, 2, 1, 2));
    Openbtn.setBorder(brdr);
    controlPanel.add(Openbtn);
Openbtn.addActionListener(new ActionListener() {

    System.out.println("Somthing");
}
公共类Opensbt扩展SBT实现ActionListener{
选择静态字符串=”;
int i=0;
int j=0;
私有静态最终长serialVersionUID=1581268288151208369L;
JButton Openbtn=新JButton(“打开”);
//@抑制警告(“弃用”)
@凌驾
已执行的公共无效操作(操作事件e){
System.out.println(“第二”);
AbstractBorder brdr=新文本BubbleOrder(Color.LIGHT\u GRAY,1,8,0);
fileopen=新的JInternalFrame(“打开”,真,真,假,假);
fileopen.setDefaultCloseOperation(JFrame.DISPOSE\u ON\u CLOSE);
fileopen.setSize(200200);
fileopen.setboorder(brdr);
fileopen.setBounds(0,2145,30);
添加(文件打开);
JPanel jp=newjpanel(newgridbaglayout());
jp.setPreferredSize(新尺寸(300200));
GridBagConstraints firstCol=新的GridBagConstraints();
firstCol.anchor=gridbagstraints.WEST;
GridBagConstraints lastCol=新的GridBagConstraints();
lastCol.gridwidth=GridBagConstraints.Requirement;
lastCol.fill=GridBagConstraints.HORIZONTAL;
列表lb=新列表(2);
lb.立根背景(颜色:白色);
l_标签=新的JLabel(“”)
+“打开文件:”;
jp.add(l_标签,第一列);
jp.add(l_标签,第一列);
lastCol.gridwidth=GridBagConstraints.Requirement;
lastCol.fill=GridBagConstraints.VERTICAL;
jp.add(lb);;
setMargin(新java.awt.Insets(1,2,1,2));
Openbtn.订单(brdr);
添加(Openbtn);
Openbtn.addActionListener(新的ActionListener(){
System.out.println(“Somthing”);
}

我不明白为什么会发生这种情况。
actionPerformed()
为什么会根据所拨打的电话或当前的电话号码执行?

我相信问题在于您的
JButton Openbtn
。 每次调用类的actionPerformed时,您都会将另一个action侦听器添加到同一个JButton。这意味着您越频繁地这样做,输出中写入“Somthing”的次数就越多


您需要在
actionPerformed()的开头再次调用
JButton Openbtn=newjbutton(“Open”);
method.

我不知道你在说什么。也许你应该发布你遇到问题的实际代码。这里的问题是什么?与其含糊其辞地描述你的代码,为什么不实际显示演示问题的代码,并在代码中指出问题所在?@Santhosh Apna code upload kijiy请。代码是dekhne dijiye。问题是matlab samajna mushkil hojayega。您在哪里实例化/使用Opensbt?谢谢,它工作正常。