Creating a simple GUI in Java can be accomplished using the Swing framework, which provides a set of components for building graphical user interfaces. Below is an example of a basic Java application that creates a window with a button. When the button is clicked, a message is displayed.
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class SimpleGUI {
public static void main(String[] args) {
JFrame frame = new JFrame("Simple GUI Example");
JPanel panel = new JPanel();
JButton button = new JButton("Click Me!");
button.addActionListener(e -> JOptionPane.showMessageDialog(frame, "Button clicked!"));
panel.add(button);
frame.add(panel);
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?