Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- public class Example2 {
- public static void main(String[] args) {
- SwingUtilities.invokeLater(() -> {
- JLabel label = new JLabel("Click the button!");
- JPanel labelPanel = new JPanel();
- labelPanel.add(label);
- JButton bt = new JButton("Click me");
- bt.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 64));
- JPanel centerPanel = new JPanel();
- int eb = 20;
- centerPanel.setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
- centerPanel.add(bt);
- JPanel mainPanel = new JPanel(new BorderLayout());
- mainPanel.add(labelPanel, BorderLayout.PAGE_START);
- mainPanel.add(centerPanel, BorderLayout.CENTER);
- JFrame frame = new JFrame("GUI");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.add(mainPanel);
- frame.pack();
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- });
- }
- }
Add Comment
Please, Sign In to add comment