Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- public class testTeamNameFrame extends JFrame {
- /** Creates new form testTeamNameFrame */
- public testTeamNameFrame() {
- createGUI();
- }
- @SuppressWarnings("unchecked")
- private void createGUI() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- JLabel howLabel = new JLabel("How many teams do you have? ");
- JTextField howField = new JTextField();
- howField.setMaximumSize(howField.getPreferredSize());
- howField.setColumns(2);
- JPanel panel1 = new JPanel();
- panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
- panel1.add(howLabel);
- panel1.add(Box.createHorizontalGlue());
- panel1.add(howField);
- JButton enterButton = new JButton("Enter Team Names");
- JButton startButton = new JButton("Start Game");
- JPanel panel2 = new JPanel();
- panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));
- panel2.add(enterButton);
- panel2.add(Box.createHorizontalGlue());
- panel2.add(startButton);
- int numTeams = 4;
- int numPanels = (numTeams+1)/2;
- JLabel teamLabels[] = new JLabel[numTeams];
- JTextField teamFields[] = new JTextField[numTeams];
- JPanel teamPanels[] = new JPanel[numPanels];
- for (int i=0; i<numTeams; i++)
- {
- teamLabels[i] = new JLabel("Team " + (i+1));
- teamFields[i] = new JTextField();
- teamFields[i].setColumns(7);
- teamFields[i].setMaximumSize(teamFields[i].getPreferredSize());
- }
- for (int i=0; i<numPanels; i++)
- {
- teamPanels[i] = new JPanel();
- teamPanels[i].setLayout(new BoxLayout(teamPanels[i], BoxLayout.X_AXIS));
- teamPanels[i].add(teamLabels[i*2]);
- teamPanels[i].add(Box.createRigidArea(new Dimension(7,0)));
- teamPanels[i].add(teamFields[i*2]);
- teamPanels[i].add(Box.createHorizontalGlue());
- teamPanels[i].add(teamLabels[(i*2)+1]);
- teamPanels[i].add(Box.createRigidArea(new Dimension(7,0)));
- teamPanels[i].add(teamFields[(i*2)+1]);
- }
- JPanel bigPanel = new JPanel();
- bigPanel.setLayout(new BoxLayout(bigPanel, BoxLayout.Y_AXIS));
- bigPanel.add(Box.createVerticalGlue());
- bigPanel.add(panel1);
- bigPanel.add(Box.createRigidArea(new Dimension(0, 10)));
- bigPanel.add(panel2);
- bigPanel.add(Box.createRigidArea(new Dimension(0, 10)));
- for (int i=0; i<numPanels; i++)
- {
- bigPanel.add(teamPanels[i]);
- bigPanel.add(Box.createRigidArea(new Dimension(0, 10)));
- }
- bigPanel.add(Box.createVerticalGlue());
- setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
- add(Box.createHorizontalGlue());
- add(bigPanel);
- add(Box.createHorizontalGlue());
- pack();
- }
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new testTeamNameFrame().setVisible(true);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement