Advertisement
Guest User

Untitled

a guest
May 27th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.19 KB | None | 0 0
  1. package Connect_4;
  2.  
  3. import java.awt.GridLayout;
  4.  
  5. import javax.swing.JComboBox;
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.GroupLayout;
  9. import javax.swing.GroupLayout.Alignment;
  10. import javax.swing.LayoutStyle.ComponentPlacement;
  11.  
  12. import java.awt.Color;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.BorderLayout;
  16.  
  17. public class StartScreen extends javax.swing.JFrame  {
  18.     /**
  19.      *
  20.      */
  21.     private static final long serialVersionUID = 1L;
  22.  
  23.     /**
  24.      *
  25.      */
  26.    
  27.     public StartScreen() {
  28.         setStartScreen();
  29.     }
  30.    
  31.     private void setStartScreen(){
  32.         GameController g = GameController.getInstance();
  33.         //Window title.
  34.         setTitle("Connect Four");
  35.         setSize(436, 301);
  36.         //Default close operation and center the window.
  37.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  38.         setLocationRelativeTo(null);
  39.         //Button Panel.
  40.         buttonPanel = new javax.swing.JPanel();
  41.         buttonPanel.setBackground(Color.BLACK);
  42.        
  43.         //Play button.
  44.  
  45.         getContentPane().add(buttonPanel, BorderLayout.EAST);
  46.         playButton = new javax.swing.JButton();
  47.         playButton.addActionListener(new ActionListener() {
  48.             public void actionPerformed(ActionEvent e) {
  49.                 GameGUI frame = new GameGUI();
  50.                 frame.setVisible(true);  
  51.                 frame.setTitle("CONNECT 4");
  52.                 frame.setResizable(false);
  53.                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);              
  54.             }
  55.         });
  56.         playButton.setForeground(Color.LIGHT_GRAY);
  57.         playButton.setBackground(Color.LIGHT_GRAY);
  58.         playButton.setFont(new java.awt.Font("Garamond", 1, 14));
  59.         playButton.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
  60.         playButton.setText("PLAY");
  61.        
  62.         //Difficulty settings drop down menu.
  63.         String [] difficultySettings = {"Human", "EasyAI", "MediumAI" };
  64.         JComboBox difficultyList1 = new JComboBox(difficultySettings);
  65.         JComboBox difficultyList2 = new JComboBox(difficultySettings);
  66.        
  67.         //Difficulty List 1.
  68.         difficultyList1.setForeground(Color.LIGHT_GRAY);
  69.         difficultyList1.setBackground(Color.BLACK);
  70.         difficultyList1.setFont(new java.awt.Font("Garamond", 1, 14));
  71.         difficultyList1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
  72.        
  73.         //Difficulty List 2
  74.         difficultyList2.setForeground(Color.LIGHT_GRAY);
  75.         difficultyList2.setBackground(Color.BLACK);
  76.         difficultyList2.setFont(new java.awt.Font("Garamond", 1, 14));
  77.         difficultyList2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
  78.        
  79.         //Load Button.
  80.         loadButton = new javax.swing.JButton();
  81.         loadButton.setForeground(Color.LIGHT_GRAY);
  82.         loadButton.setBackground(Color.LIGHT_GRAY);
  83.         loadButton.setFont(new java.awt.Font("Garamond", 1, 14));
  84.         loadButton.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
  85.         loadButton.setText("LOAD");
  86.        
  87.         //Quit Button.
  88.         quitButton = new javax.swing.JButton();
  89.         quitButton.addActionListener(new ActionListener() {
  90.             public void actionPerformed(ActionEvent e) {
  91.                 System.exit(0);
  92.             }
  93.         });
  94.         quitButton.setForeground(Color.LIGHT_GRAY);
  95.         quitButton.setBackground(Color.LIGHT_GRAY);
  96.         quitButton.setFont(new java.awt.Font("Garamond", 1, 14));
  97.         quitButton.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));
  98.         quitButton.setText("QUIT");
  99.         GroupLayout gl_buttonPanel = new GroupLayout(buttonPanel);
  100.         gl_buttonPanel.setHorizontalGroup(
  101.             gl_buttonPanel.createParallelGroup(Alignment.LEADING)
  102.                 .addGroup(gl_buttonPanel.createSequentialGroup()
  103.                     .addContainerGap(119, Short.MAX_VALUE)
  104.                     .addGroup(gl_buttonPanel.createParallelGroup(Alignment.TRAILING)
  105.                         .addGroup(gl_buttonPanel.createSequentialGroup()
  106.                             .addComponent(difficultyList2, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)
  107.                             .addGap(58)
  108.                             .addComponent(difficultyList1, GroupLayout.PREFERRED_SIZE, 108, GroupLayout.PREFERRED_SIZE)
  109.                             .addGap(90))
  110.                         .addGroup(gl_buttonPanel.createSequentialGroup()
  111.                             .addGroup(gl_buttonPanel.createParallelGroup(Alignment.LEADING)
  112.                                 .addComponent(loadButton, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
  113.                                 .addComponent(playButton, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE))
  114.                             .addGap(152))
  115.                         .addGroup(gl_buttonPanel.createSequentialGroup()
  116.                             .addComponent(quitButton, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
  117.                             .addGap(151))))
  118.         );
  119.         gl_buttonPanel.setVerticalGroup(
  120.             gl_buttonPanel.createParallelGroup(Alignment.LEADING)
  121.                 .addGroup(gl_buttonPanel.createSequentialGroup()
  122.                     .addGap(21)
  123.                     .addComponent(playButton, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
  124.                     .addPreferredGap(ComponentPlacement.RELATED)
  125.                     .addComponent(loadButton, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
  126.                     .addPreferredGap(ComponentPlacement.RELATED)
  127.                     .addGroup(gl_buttonPanel.createParallelGroup(Alignment.BASELINE)
  128.                         .addComponent(difficultyList2, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
  129.                         .addComponent(difficultyList1, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE))
  130.                     .addGap(18)
  131.                     .addComponent(quitButton, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
  132.                     .addContainerGap(47, Short.MAX_VALUE))
  133.         );
  134.         buttonPanel.setLayout(gl_buttonPanel);
  135.         buttonPanel.repaint();
  136.         buttonPanel.setVisible(true);
  137.        
  138.     }
  139.    
  140.    
  141.     public static void main(String args[]) {
  142.          
  143.            // Create and display the form
  144.            java.awt.EventQueue.invokeLater(new Runnable(){
  145.                public void run() {
  146.                  
  147.                    new StartScreen().setVisible(true);
  148.                }
  149.            });
  150.         }
  151.    
  152.    
  153.     private JComboBox difficultyList1;
  154.     private JComboBox difficulatyList2;
  155.     private String[] difficultySettings;
  156.     private JPanel buttonPanel;
  157.     private javax.swing.JButton playButton;
  158.     private javax.swing.JButton loadButton;
  159.     private javax.swing.JButton quitButton;
  160.    
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement