为每个用户输入添加对象
Add object for every user input
我试图在每次用户按下按钮时创建一个新按钮。
因此,如果我单击 "add" 按钮,则会将一个新的 panel/button/thing 添加到 JPanel。
不确定 this 是否与我要求的相同
不知道是什么
guiButtons[0]
在
if(buttonClick.getSource().equals(guiButtons[0]))
如果有人能解释一下就好了
您可以试试下面的代码,希望对您有所帮助
JPanel panel = new JPanel(new FlowLayout());
JButton button = new JButton("Add");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton newButton = new JButton("New Added Bnt");
panel.add(newButton);
}
});
我试图在每次用户按下按钮时创建一个新按钮。
因此,如果我单击 "add" 按钮,则会将一个新的 panel/button/thing 添加到 JPanel。
不确定 this 是否与我要求的相同
不知道是什么
guiButtons[0]
在
if(buttonClick.getSource().equals(guiButtons[0]))
如果有人能解释一下就好了
您可以试试下面的代码,希望对您有所帮助
JPanel panel = new JPanel(new FlowLayout());
JButton button = new JButton("Add");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton newButton = new JButton("New Added Bnt");
panel.add(newButton);
}
});