[Solved] how do i create a method that generates a JButton? [closed]


You can of course write a method that creates JButton for you:

public JButton createButton(String label, ActionListener listener, int x, int y) {
  JButton b = new JButton(label);
  name.addActionListener(listener);
  name.setBounds(x, y, 150, 50);
  return b;
}

and then use the method like this:

button19 = createButton("Toiletsager", this, 100, 100);

You can of course also specify one ActionListener for each button:

button20 = createButton("Toiletsager", e->System.out.println(e) , 100, 100);

1

solved how do i create a method that generates a JButton? [closed]