How to add a button to my GUI Application in Java
Hello everyone, hope your day is going well so far! I wan to add a button to my GUI application but I'm not sure on how i would do that. Here the code that I already have: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class AddressBook extends JPanel{ public static void main(String[] args) { //Creating the frame JFrame frame = new JFrame("AddressBook"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Creating a panel JPanel panel = new JPanel(); panel.setBackground(Color.white); panel.setPreferredSize(new Dimension(250,250)); //Creating labels and text fields JLabel label1 = new JLabel("Username"); JLabel label2 = new JLabel("Password"); JTextField text1 = new JTextField(30); JTextField text2 = new JTextField(30); panel.add(label1); panel.add(text1); panel.add(label2); panel.add(text2); //Adding the panel to the frame frame.getContentPane().add(panel); //Crucial frame.pack(); frame.setVisible(true); //Creating a submit button } }