Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4.  
  5. public class testTeamNameFrame extends JFrame {
  6.  
  7.     /** Creates new form testTeamNameFrame */
  8.     public testTeamNameFrame() {
  9.         createGUI();
  10.     }
  11.  
  12.     @SuppressWarnings("unchecked")
  13.  
  14.     private void createGUI() {
  15.  
  16.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  17.         JLabel howLabel = new JLabel("How many teams do you have? ");
  18.         JTextField howField = new JTextField();
  19.         howField.setMaximumSize(howField.getPreferredSize());
  20.         howField.setColumns(2);
  21.         JPanel panel1 = new JPanel();
  22.         panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
  23.         panel1.add(howLabel);
  24.         panel1.add(Box.createHorizontalGlue());
  25.         panel1.add(howField);
  26.  
  27.         JButton enterButton = new JButton("Enter Team Names");
  28.         JButton startButton = new JButton("Start Game");
  29.         JPanel panel2 = new JPanel();
  30.         panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));
  31.         panel2.add(enterButton);
  32.         panel2.add(Box.createHorizontalGlue());
  33.         panel2.add(startButton);
  34.  
  35.         int numTeams = 4;
  36.         int numPanels = (numTeams+1)/2;
  37.  
  38.         JLabel teamLabels[] = new JLabel[numTeams];
  39.         JTextField teamFields[] = new JTextField[numTeams];
  40.         JPanel teamPanels[] = new JPanel[numPanels];
  41.         for (int i=0; i<numTeams; i++)
  42.         {
  43.             teamLabels[i] = new JLabel("Team " + (i+1));
  44.             teamFields[i] = new JTextField();
  45.             teamFields[i].setColumns(7);
  46.             teamFields[i].setMaximumSize(teamFields[i].getPreferredSize());
  47.         }
  48.  
  49.         for (int i=0; i<numPanels; i++)
  50.         {
  51.             teamPanels[i] = new JPanel();
  52.             teamPanels[i].setLayout(new BoxLayout(teamPanels[i], BoxLayout.X_AXIS));
  53.             teamPanels[i].add(teamLabels[i*2]);
  54.             teamPanels[i].add(Box.createRigidArea(new Dimension(7,0)));
  55.             teamPanels[i].add(teamFields[i*2]);
  56.             teamPanels[i].add(Box.createHorizontalGlue());
  57.             teamPanels[i].add(teamLabels[(i*2)+1]);
  58.             teamPanels[i].add(Box.createRigidArea(new Dimension(7,0)));
  59.             teamPanels[i].add(teamFields[(i*2)+1]);
  60.         }
  61.  
  62.         JPanel bigPanel = new JPanel();
  63.         bigPanel.setLayout(new BoxLayout(bigPanel, BoxLayout.Y_AXIS));
  64.         bigPanel.add(Box.createVerticalGlue());
  65.         bigPanel.add(panel1);
  66.         bigPanel.add(Box.createRigidArea(new Dimension(0, 10)));
  67.         bigPanel.add(panel2);
  68.         bigPanel.add(Box.createRigidArea(new Dimension(0, 10)));
  69.         for (int i=0; i<numPanels; i++)
  70.         {
  71.             bigPanel.add(teamPanels[i]);
  72.             bigPanel.add(Box.createRigidArea(new Dimension(0, 10)));
  73.         }
  74.         bigPanel.add(Box.createVerticalGlue());
  75.  
  76.         setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
  77.         add(Box.createHorizontalGlue());
  78.         add(bigPanel);
  79.         add(Box.createHorizontalGlue());
  80.         pack();
  81.  
  82.     }
  83.  
  84.     public static void main(String args[]) {
  85.         java.awt.EventQueue.invokeLater(new Runnable() {
  86.             public void run() {
  87.                 new testTeamNameFrame().setVisible(true);
  88.             }
  89.         });
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement