Java GUI Programming (Swing/JavaFX)
Java GUI Programming (Swing/JavaFX)
Building graphical user interfaces in Java can be done using Swing or JavaFX. Both frameworks
allow developers to create rich desktop applications with interactive components.
Key Concepts:
- Swing Components: JFrame, JPanel, JButton, JLabel, etc.
- Event Handling: Listening and responding to user actions like button clicks.
- Layout Managers: Organizing components using layouts such as BorderLayout, FlowLayout, etc.
- JavaFX: A more modern UI toolkit with CSS styling and hardware-accelerated graphics.
Example (Swing):
--------------------------------
import javax.swing.*;
public class SimpleGUI {
public static void main(String[] args) {
JFrame frame = new JFrame("My GUI");
JButton button = new JButton("Click Me");
frame.add(button);
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
--------------------------------