Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Button;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import javax.swing.*;
- public class MainClass {
- public static void addComponentsToPane(Container pane) {
- pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
- addAButton("Single player", pane);
- addAButton("Multy player", pane);
- addAButton("Controls", pane);
- addAButton("About", pane);
- addAButton("Exit", pane);
- }
- private static void addAButton(String text, Container container) {
- JButton button = new JButton(text);
- button.setAlignmentX(Component.CENTER_ALIGNMENT);
- container.add(button);
- }
- /*
- * Create the GUI and show it.
- */
- private static void createAndShowGUI() {
- //Create and set up the window.
- JFrame frame = new JFrame("Game frame");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Set up the content pane.
- addComponentsToPane(frame.getContentPane());
- //Display the window.
- frame.setSize(800, 800);
- frame.getContentPane().setBackground(Color.GREEN);
- frame.setTitle("Pong");
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- //creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment