write me on java simple gui
- User
write me on java simple gui
- Assistant
Sure, I can provide you with a simple Java GUI example. Here's a basic program that opens a window with a button and displays a message when the button is clicked:
codeimport javax.swing.*; public class SimpleGUI { public static void main(String[] args) { JFrame frame = new JFrame("My GUI"); JPanel panel = new JPanel(); JButton button = new JButton("Click Me"); button.addActionListener(e -> JOptionPane.showMessageDialog(null, "Hello World!")); panel.add(button); frame.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }