Untitled
unknown
java
3 years ago
858 B
6
Indexable
import javax.swing.JButton;
import javax.swing.JFrame;
public class ButtonExample {
public static void main(String[] args) {
// Create a JFrame window
JFrame frame = new JFrame("Button Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
// Create a JButton
JButton button = new JButton("Click Me!");
button.setBounds(100, 50, 100, 40); // Set the position and size of the button
// Add a lambda expression as an action listener to the button
button.addActionListener(e -> {
System.out.println("Button clicked!");
// Perform any desired actions here
});
// Add the button to the JFrame
frame.getContentPane().add(button);
// Display the JFrame
frame.setVisible(true);
}
}
Editor is loading...