I have created a set of buttons that I want to be at the top of every page of my application.
Rather than having to recreate the setup in every class, is it possible to create it once and include it in every class, similar to a reusable view in Android.
My code for the button setup is below:
public Buttons() {
setLayout(null);
JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(10, 11, 89, 23);
add(btnNewButton);
JButton btnNewButton_1 = new JButton("New button");
btnNewButton_1.setBounds(101, 11, 89, 23);
add(btnNewButton_1);
JButton btnNewButton_2 = new JButton("New button");
btnNewButton_2.setBounds(192, 11, 89, 23);
add(btnNewButton_2);
textField_2 = new JTextField();
textField_2.setBounds(104, 42, 86, 20);
add(textField_2);
textField_2.setColumns(10);
System.out.println("HELLO");
}
My code to create the class is below:
public static void gui(){
frame = new JFrame("name");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(true);
frame.setLayout(new BorderLayout());
frame.add(new Buttons(), BorderLayout.WEST);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setBounds(200, 0, 500, 500);
}
I have tried adding the following line to this method to add a second set of buttons:
frame.add(new Extras(), BorderLayout.CENTER);
but it only adds the second object to the display.