我正在尝试动态添加按钮(JButtons),它每次都会更改名称.我用for循环做它并没有真正的问题.但是当添加一个动作监听器或识别哪个按钮被按下时,那就是当事情不能很好地工作时.
MyFrame.java
import javax.swing.*;
import java.awt.event.*;
import java.awt.GridLayout;
public class MyFrame extends JFrame implements ActionListener
{
private JPanel panel;
private static JButton[] buttons = new JButton[18];
// set all static calculate JButtons
private static JButton equalsBtn, addBtn, subBtn, multiBtn, divBtn, clearBtn, plusMinusBtn, decimalBtn;
// set all static number JBtuttons
private static JButton zeroBtn, oneBtn, twoBtn, threeBtn, fourBtn, fiveBtn, sixBtn, sevenBtn, eightBtn, nineBtn;
private static JTextField resultField;
// numOne is the first row of figures en the second numSecond is the …Run Code Online (Sandbox Code Playgroud)