Svetli0o

UI

May 15th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. import java.awt.Button;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5.  
  6. import javax.swing.*;
  7.  
  8. public class MainClass {
  9.     public static void addComponentsToPane(Container pane) {
  10.         pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
  11.        
  12.         addAButton("Single player", pane);
  13.         addAButton("Multy player", pane);
  14.         addAButton("Controls", pane);
  15.         addAButton("About", pane);
  16.         addAButton("Exit", pane);
  17.     }
  18.  
  19.     private static void addAButton(String text, Container container) {
  20.         JButton button = new JButton(text);
  21.         button.setAlignmentX(Component.CENTER_ALIGNMENT);
  22.         container.add(button);
  23.     }
  24.  
  25.     /*
  26.      * Create the GUI and show it.
  27.      */
  28.     private static void createAndShowGUI() {
  29.         //Create and set up the window.
  30.         JFrame frame = new JFrame("Game frame");
  31.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.  
  33.         //Set up the content pane.
  34.         addComponentsToPane(frame.getContentPane());
  35.         //Display the window.
  36.         frame.setSize(800, 800);
  37.         frame.getContentPane().setBackground(Color.GREEN);
  38.         frame.setTitle("Pong");
  39.         frame.setLocationRelativeTo(null);
  40.         frame.setVisible(true);
  41.     }
  42.  
  43.     public static void main(String[] args) {
  44.         //creating and showing this application's GUI.
  45.         javax.swing.SwingUtilities.invokeLater(new Runnable() {
  46.             public void run() {
  47.                 createAndShowGUI();
  48.             }
  49.         });
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment