Results 1 to 5 of 5
  1. #1
    eckt is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default GUI with java.lang.IllegalStateException

    Hello everybody,

    I'm having some problems with a GUI application. I wanted to do a really nice layout so I created it in the Netbeans editor, copied it into eclipse and started working on it. Now I get an Illegal State Exception and I have no idea where the problem is! I've inserted the sourcecode and hope that you guys can help!
    Thanks a bunch!

    Best regards,
    Emma

    P.S. i'm sorry it's so messy!

    Java Code:
    package gui;
    
    import helpers.Const;
    
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.net.UnknownHostException;
    
    import javax.swing.BorderFactory;
    import javax.swing.GroupLayout;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.LayoutStyle.ComponentPlacement;
    import javax.swing.border.LineBorder;
    
    import launchers.Launcher;
    
    @SuppressWarnings("serial")
    public class GUI extends JFrame implements Runnable {
    
    	// Variables declaration - do not modify
    	private JPanel AISkillPanel;
    	private JPanel ClientPanel;
    	private JPanel ServerPanel;
    	private JCheckBox aiDebugCheckBox;
    	private JLabel aiDebugLabel;
    	private JComboBox aiSkillList;
    	private JLabel aiSkillLabel;
    	private JPanel buttonPanel;
    	private JButton clientButton;
    	private JLabel clientTextField;
    	private JCheckBox destructablesCheckBox;
    	private JLabel destructablesLabel;
    	private JPanel destructablesPanel;
    	private JLabel generateLabel;
    	private JPanel innerClientPanel;
    	private JPanel innerServerPanel;
    	private JComboBox IPList;
    	private JLabel ipLabel;
    	private JPanel ipPanel;
    	private JComboBox maxPlayersList;
    	private JLabel maxPlayersLabel;
    	private JPanel maxPlayersPanel;
    	private JCheckBox networkLogClientCheckBox;
    	private JCheckBox networkLogServerCheckBox;
    	private JComboBox performanceList;
    	private JLabel performanceLabel;
    	private JPanel performancePanel;
    	private JPanel aiDebugPanel;
    	private JLabel clientPortLabel;
    	private JLabel serverPortLabel;
    	private JPanel clientPortPanel;
    	private JPanel serverPortPanel;
    	private JTextField clientPortTextField;
    	private JTextField serverPortTextField;
    	private JButton serverButton;
    	private JPanel serverButtonPanel;
    	private JLabel serverTextField;
    	private String IP;
    	private String IPcurrent;
    	public int maxPlayers;
    
    	// End of variables declaration
    
    	public GUI() {
    		setVisible(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setTitle("Start Bomberman");
    		setLocation(200, 150);
    		setResizable(false);
    		initComponents();
    	}
    
    	private void initComponents() {
    
    		this.ClientPanel = new JPanel();
    		this.clientTextField = new JLabel();
    		this.innerClientPanel = new JPanel();
    		this.ipPanel = new JPanel();
    		this.ipLabel = new JLabel();
    		this.clientPortPanel = new JPanel();
    		this.clientPortLabel = new JLabel();
    		this.clientPortTextField = new JTextField();
    		this.aiDebugPanel = new JPanel();
    		this.aiDebugLabel = new JLabel();
    		this.aiDebugCheckBox = new JCheckBox();
    		this.buttonPanel = new JPanel();
    		this.clientButton = new JButton();
    		this.networkLogClientCheckBox = new JCheckBox();
    		this.performancePanel = new JPanel();
    		this.performanceLabel = new JLabel();
    		this.ServerPanel = new JPanel();
    		this.serverTextField = new JLabel();
    		this.innerServerPanel = new JPanel();
    		this.maxPlayersPanel = new JPanel();
    		this.maxPlayersLabel = new JLabel();
    		this.maxPlayersList = new JComboBox();
    		this.AISkillPanel = new JPanel();
    		this.aiSkillLabel = new JLabel();
    		this.aiSkillList = new JComboBox();
    		this.serverPortPanel = new JPanel();
    		this.serverPortLabel = new JLabel();
    		this.serverPortTextField = new JTextField();
    		this.destructablesPanel = new JPanel();
    		this.generateLabel = new JLabel();
    		this.destructablesLabel = new JLabel();
    		this.destructablesCheckBox = new JCheckBox();
    		this.serverButtonPanel = new JPanel();
    		this.serverButton = new JButton();
    		this.networkLogServerCheckBox = new JCheckBox();
    
    		this.ClientPanel.setBorder(new LineBorder(new Color(204, 0, 0), 3, true));
    
    		this.clientTextField.setFont(new Font("Tahoma", 1, 14));
    		this.clientTextField.setText("CLIENT");
    
    		innerClientPanel.setBorder(BorderFactory.createEtchedBorder());
    
    		this.ipPanel.setBorder(BorderFactory.createEtchedBorder());
    		this.ipPanel.setMaximumSize(new Dimension(190, 43));
    		this.ipPanel.setMinimumSize(new Dimension(190, 43));
    		this.ipPanel.setPreferredSize(new Dimension(190, 43));
    
    		this.ipLabel.setFont(new Font("Tahoma", 0, 12));
    		this.ipLabel.setText("IP:");
    
    		try {
    			this.IP = java.net.InetAddress.getLocalHost().getHostAddress();
    		} catch (UnknownHostException e) {
    			System.err.println("Could not get server ip");
    			System.exit(1);
    		}
    
    		String[] IPchoices = { "localhost", IP };
    
    		this.IPcurrent = IPchoices[0];
    
    		this.IPList = new JComboBox(IPchoices);
    		this.IPList.setEditable(true);
    		IPList.addActionListener(new ActionListener() {
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				JComboBox cb = (JComboBox) e.getSource();
    				String newSelection = (String) cb.getSelectedItem();
    				IPcurrent = newSelection;
    			}
    		});
    
    		GroupLayout ipPanelLayout = new GroupLayout(this.ipPanel);
    		this.ipPanel.setLayout(ipPanelLayout);
    		ipPanelLayout.setHorizontalGroup(ipPanelLayout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addGroup(
    				ipPanelLayout.createSequentialGroup().addContainerGap()
    						.addComponent(this.ipLabel)
    						.addPreferredGap(ComponentPlacement.RELATED, 20,
    								Short.MAX_VALUE).addComponent(IPList,
    								GroupLayout.PREFERRED_SIZE,
    								GroupLayout.DEFAULT_SIZE,
    								GroupLayout.PREFERRED_SIZE).addContainerGap()));
    		ipPanelLayout.setVerticalGroup(ipPanelLayout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addGroup(
    				ipPanelLayout.createSequentialGroup().addContainerGap()
    						.addGroup(
    								ipPanelLayout.createParallelGroup(
    										GroupLayout.Alignment.BASELINE)
    										.addComponent(this.ipLabel).addComponent(
    												IPList,
    												GroupLayout.PREFERRED_SIZE,
    												GroupLayout.DEFAULT_SIZE,
    												GroupLayout.PREFERRED_SIZE))
    						.addContainerGap(GroupLayout.DEFAULT_SIZE,
    								Short.MAX_VALUE)));
    
    		this.clientPortPanel.setBorder(BorderFactory.createEtchedBorder());
    		this.clientPortPanel.setMaximumSize(new Dimension(190, 43));
    		this.clientPortPanel.setMinimumSize(new Dimension(190, 43));
    		this.clientPortPanel.setPreferredSize(new Dimension(190, 43));
    
    		this.clientPortLabel.setFont(new Font("Tahoma", 0, 12));
    		this.clientPortLabel.setText("Port:");
    
    		this.clientPortTextField.setText("4444");
    
    		GroupLayout clientPortPanelLayout = new GroupLayout(this.clientPortPanel);
    		this.clientPortPanel.setLayout(clientPortPanelLayout);
    		clientPortPanelLayout
    				.setHorizontalGroup(clientPortPanelLayout.createParallelGroup(
    						GroupLayout.Alignment.LEADING).addGroup(
    						clientPortPanelLayout.createSequentialGroup()
    								.addContainerGap()
    								.addComponent(this.clientPortLabel).addPreferredGap(
    										ComponentPlacement.RELATED, 76,
    										Short.MAX_VALUE).addComponent(
    										this.clientPortTextField,
    										GroupLayout.PREFERRED_SIZE, 40,
    										GroupLayout.PREFERRED_SIZE).addGap(33,
    										33, 33)));
    		clientPortPanelLayout.setVerticalGroup(clientPortPanelLayout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addGroup(
    				clientPortPanelLayout.createSequentialGroup().addContainerGap()
    						.addGroup(
    								clientPortPanelLayout.createParallelGroup(
    										GroupLayout.Alignment.BASELINE)
    										.addComponent(this.clientPortLabel)
    										.addComponent(this.clientPortTextField,
    												GroupLayout.PREFERRED_SIZE,
    												GroupLayout.DEFAULT_SIZE,
    												GroupLayout.PREFERRED_SIZE))
    						.addContainerGap(GroupLayout.DEFAULT_SIZE,
    								Short.MAX_VALUE)));
    
    		this.aiDebugPanel.setBorder(BorderFactory.createEtchedBorder());
    		this.aiDebugPanel.setMaximumSize(new Dimension(190, 43));
    		this.aiDebugPanel.setMinimumSize(new Dimension(190, 43));
    		this.aiDebugPanel.setPreferredSize(new Dimension(190, 43));
    
    		this.aiDebugLabel.setFont(new Font("Tahoma", 0, 12));
    		this.aiDebugLabel.setText("AI debug:");
    
    		this.aiDebugCheckBox.setLabel("On/Off");
    		this.aiDebugCheckBox.addItemListener(new CheckBoxListener());
    		this.aiDebugCheckBox.setSelected(false);
    
    		GroupLayout aiDebugPanelLayout = new GroupLayout(this.aiDebugPanel);
    		this.aiDebugPanel.setLayout(aiDebugPanelLayout);
    		aiDebugPanelLayout.setHorizontalGroup(aiDebugPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						aiDebugPanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(this.aiDebugLabel)
    								.addPreferredGap(ComponentPlacement.RELATED,
    										48, Short.MAX_VALUE).addComponent(
    										this.aiDebugCheckBox).addGap(14, 14, 14)));
    		aiDebugPanelLayout.setVerticalGroup(aiDebugPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						aiDebugPanelLayout.createSequentialGroup()
    								.addContainerGap().addGroup(
    										aiDebugPanelLayout.createParallelGroup(
    												GroupLayout.Alignment.BASELINE)
    												.addComponent(this.aiDebugLabel)
    												.addComponent(this.aiDebugCheckBox))
    								.addContainerGap(8, Short.MAX_VALUE)));
    
    		this.clientButton.setFont(new Font("Tahoma", 1, 11));
    		this.clientButton.setText("Start Client");
    		this.clientButton.addActionListener(new ButtonListener());
    
    		this.networkLogClientCheckBox.setLabel("Network log");
    		this.networkLogClientCheckBox.addItemListener(new CheckBoxListener());
    
    		GroupLayout buttonPanelLayout = new GroupLayout(this.buttonPanel);
    		this.buttonPanel.setLayout(buttonPanelLayout);
    		buttonPanelLayout.setHorizontalGroup(buttonPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						buttonPanelLayout.createSequentialGroup().addComponent(
    								this.clientButton).addPreferredGap(
    								ComponentPlacement.RELATED, 4, Short.MAX_VALUE)
    								.addComponent(this.networkLogClientCheckBox)
    								.addContainerGap()));
    		buttonPanelLayout
    				.setVerticalGroup(buttonPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								GroupLayout.Alignment.TRAILING,
    								buttonPanelLayout
    										.createSequentialGroup()
    										.addContainerGap(
    												GroupLayout.DEFAULT_SIZE,
    												Short.MAX_VALUE)
    										.addGroup(
    												buttonPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(
    																this.clientButton)
    														.addComponent(
    																this.networkLogClientCheckBox))));
    
    		this.performancePanel.setBorder(BorderFactory.createEtchedBorder());
    		this.performancePanel.setMaximumSize(new Dimension(190, 43));
    		this.performancePanel.setMinimumSize(new Dimension(190, 43));
    		this.performancePanel.setPreferredSize(new Dimension(190, 43));
    
    		this.performanceLabel.setFont(new Font("Tahoma", 0, 12));
    		this.performanceLabel.setText("Performance:");
    
    		String[] performanceChoices = { "Low", "High" };
    		this.performanceList = new JComboBox(performanceChoices);
    		this.performanceList.setSelectedIndex(0);
    
    		performanceList.addActionListener(new ActionListener() {
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				JComboBox cb = (JComboBox) e.getSource();
    				String newSelection = (String) cb.getSelectedItem();
    				if (newSelection.equals("High")) {
    					Const.PERFORMANCE = Const.PERFORMANCE_HIGH;
    				} else if (newSelection.equals("Low")){
    					Const.PERFORMANCE = Const.PERFORMANCE_LOW;
    				}
    			}
    		});
    
    		GroupLayout performancePanelLayout = new GroupLayout(this.performancePanel);
    		this.performancePanel.setLayout(performancePanelLayout);
    		performancePanelLayout.setHorizontalGroup(performancePanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						performancePanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(
    										this.performanceLabel).addPreferredGap(
    										ComponentPlacement.RELATED, 30,
    										Short.MAX_VALUE).addComponent(
    										performanceList,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE).addGap(27,
    										27, 27)));
    		performancePanelLayout
    				.setVerticalGroup(performancePanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								performancePanelLayout
    										.createSequentialGroup()
    										.addContainerGap(
    												GroupLayout.DEFAULT_SIZE,
    												Short.MAX_VALUE)
    										.addGroup(
    												performancePanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(
    																this.performanceLabel)
    														.addComponent(
    																performanceList,
    																GroupLayout.PREFERRED_SIZE,
    																GroupLayout.DEFAULT_SIZE,
    																GroupLayout.PREFERRED_SIZE))
    										.addContainerGap()));
    
    		GroupLayout innerClientPanelLayout = new GroupLayout(innerClientPanel);
    		innerClientPanel.setLayout(innerClientPanelLayout);
    		innerClientPanelLayout
    				.setHorizontalGroup(innerClientPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								innerClientPanelLayout
    										.createSequentialGroup()
    										.addContainerGap()
    										.addGroup(
    												innerClientPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.LEADING)
    														.addGroup(
    																innerClientPanelLayout
    																		.createParallelGroup(
    																				GroupLayout.Alignment.TRAILING,
    																				false)
    																		.addComponent(
    																				this.aiDebugPanel,
    																				GroupLayout.Alignment.LEADING,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				Short.MAX_VALUE)
    																		.addComponent(
    																				this.ipPanel,
    																				GroupLayout.Alignment.LEADING,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				Short.MAX_VALUE)
    																		.addComponent(
    																				this.clientPortPanel,
    																				GroupLayout.Alignment.LEADING,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				Short.MAX_VALUE))
    														.addComponent(
    																this.performancePanel,
    																GroupLayout.DEFAULT_SIZE,
    																GroupLayout.DEFAULT_SIZE,
    																Short.MAX_VALUE)
    														.addComponent(
    																this.buttonPanel,
    																GroupLayout.Alignment.TRAILING,
    																GroupLayout.DEFAULT_SIZE,
    																GroupLayout.DEFAULT_SIZE,
    																Short.MAX_VALUE))
    										.addContainerGap()));
    		innerClientPanelLayout.setVerticalGroup(innerClientPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						innerClientPanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(this.ipPanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addPreferredGap(
    										ComponentPlacement.RELATED)
    								.addComponent(this.clientPortPanel,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addPreferredGap(ComponentPlacement.RELATED)
    								.addComponent(this.aiDebugPanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addPreferredGap(
    										ComponentPlacement.RELATED)
    								.addComponent(this.performancePanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addPreferredGap(
    										ComponentPlacement.RELATED)
    								.addComponent(this.buttonPanel,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addContainerGap()));
    
    		GroupLayout ClientPanelLayout = new GroupLayout(this.ClientPanel);
    		this.ClientPanel.setLayout(ClientPanelLayout);
    		ClientPanelLayout.setHorizontalGroup(ClientPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						GroupLayout.Alignment.TRAILING,
    						ClientPanelLayout.createSequentialGroup()
    								.addContainerGap(88, Short.MAX_VALUE)
    								.addComponent(this.clientTextField).addGap(92, 92,
    										92)).addGroup(
    						ClientPanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(
    										innerClientPanel,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addContainerGap(GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE)));
    		ClientPanelLayout.setVerticalGroup(ClientPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						ClientPanelLayout.createSequentialGroup()
    								.addContainerGap()
    								.addComponent(this.clientTextField).addGap(18, 18,
    										18).addComponent(innerClientPanel,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addContainerGap(14, Short.MAX_VALUE)));
    
    		this.ServerPanel.setBorder(new LineBorder(new Color(0, 51, 153), 3, true));
    
    		this.serverTextField.setFont(new Font("Tahoma", 1, 14));
    		this.serverTextField.setText("SERVER");
    
    		this.innerServerPanel.setBorder(BorderFactory.createEtchedBorder());
    
    		this.maxPlayersPanel.setBorder(BorderFactory.createEtchedBorder());
    		this.maxPlayersPanel.setMaximumSize(new Dimension(190, 43));
    		this.maxPlayersPanel.setMinimumSize(new Dimension(190, 43));
    		this.maxPlayersPanel.setPreferredSize(new Dimension(190, 43));
    
    		this.maxPlayersLabel.setFont(new Font("Tahoma", 0, 12));
    		this.maxPlayersLabel.setText("Max # of players:");
    
    		String[] maxPlayerChoices = {"2", "3", "4" };
    		this.maxPlayersList = new JComboBox(maxPlayerChoices);
    		this.maxPlayersList.setSelectedIndex(0);
    
    		this.maxPlayersList.addActionListener(new ActionListener() {
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				JComboBox cb = (JComboBox) e.getSource();
    				String newSelection = (String) cb.getSelectedItem();
    				Const.MAX_PLAYERS_IN_GAME = Integer.parseInt(newSelection);
    			}
    		});
    
    		GroupLayout maxPlayersPanelLayout = new GroupLayout(this.maxPlayersPanel);
    		this.maxPlayersPanel.setLayout(maxPlayersPanelLayout);
    		maxPlayersPanelLayout.setHorizontalGroup(maxPlayersPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						maxPlayersPanelLayout.createSequentialGroup()
    								.addContainerGap()
    								.addComponent(this.maxPlayersLabel).addGap(18, 18,
    										18).addComponent(this.maxPlayersList,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addContainerGap(33, Short.MAX_VALUE)));
    		maxPlayersPanelLayout
    				.setVerticalGroup(maxPlayersPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								maxPlayersPanelLayout
    										.createSequentialGroup()
    										.addContainerGap()
    										.addGroup(
    												maxPlayersPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(
    																this.maxPlayersLabel)
    														.addComponent(
    																this.maxPlayersList,
    																GroupLayout.PREFERRED_SIZE,
    																GroupLayout.DEFAULT_SIZE,
    																GroupLayout.PREFERRED_SIZE))
    										.addContainerGap(
    												GroupLayout.DEFAULT_SIZE,
    												Short.MAX_VALUE)));
    
    		this.AISkillPanel.setBorder(BorderFactory.createEtchedBorder());
    		this.AISkillPanel.setMaximumSize(new Dimension(190, 43));
    		this.AISkillPanel.setMinimumSize(new Dimension(190, 43));
    		this.AISkillPanel.setPreferredSize(new Dimension(190, 43));
    
    		this.aiSkillLabel.setFont(new Font("Tahoma", 0, 12));
    		this.aiSkillLabel.setText("AI skill:");
    
    		String[] aiSkillChoices = { "Easy", "Insane" };
    		this.aiSkillList = new JComboBox(aiSkillChoices);
    
    		this.aiSkillList.addActionListener(new ActionListener() {
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				JComboBox cb = (JComboBox) e.getSource();
    				String newSelection = (String) cb.getSelectedItem();
    				if (newSelection.equals("Insane")) {
    					Const.AISKILL = Const.AISKILL_INSANE;
    				} else {
    					Const.AISKILL = Const.AISKILL_EASY;
    				}
    			}
    		});
    
    		GroupLayout AISkillPanelLayout = new GroupLayout(this.AISkillPanel);
    		this.AISkillPanel.setLayout(AISkillPanelLayout);
    		AISkillPanelLayout.setHorizontalGroup(AISkillPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						AISkillPanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(this.aiSkillLabel)
    								.addPreferredGap(ComponentPlacement.RELATED,
    										71, Short.MAX_VALUE).addComponent(
    										this.aiSkillList,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addContainerGap()));
    		AISkillPanelLayout
    				.setVerticalGroup(AISkillPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								AISkillPanelLayout
    										.createSequentialGroup()
    										.addContainerGap()
    										.addGroup(
    												AISkillPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(
    																this.aiSkillLabel)
    														.addComponent(
    																this.aiSkillList,
    																GroupLayout.PREFERRED_SIZE,
    																GroupLayout.DEFAULT_SIZE,
    																GroupLayout.PREFERRED_SIZE))
    										.addContainerGap(
    												GroupLayout.DEFAULT_SIZE,
    												Short.MAX_VALUE)));
    
    		this.serverPortPanel.setBorder(BorderFactory.createEtchedBorder());
    		this.serverPortPanel.setMaximumSize(new Dimension(190, 43));
    		this.serverPortPanel.setMinimumSize(new Dimension(190, 43));
    		this.serverPortPanel.setPreferredSize(new Dimension(190, 43));
    
    		this.serverPortLabel.setFont(new Font("Tahoma", 0, 12));
    		this.serverPortLabel.setText("Port:");
    
    		this.serverPortTextField.setText("4444");
    
    		GroupLayout portPanel1Layout = new GroupLayout(this.serverPortPanel);
    		this.serverPortPanel.setLayout(portPanel1Layout);
    		portPanel1Layout.setHorizontalGroup(portPanel1Layout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						portPanel1Layout.createSequentialGroup()
    								.addContainerGap()
    								.addComponent(this.serverPortLabel).addPreferredGap(
    										ComponentPlacement.RELATED, 74,
    										Short.MAX_VALUE).addComponent(
    										this.serverPortTextField,
    										GroupLayout.PREFERRED_SIZE, 40,
    										GroupLayout.PREFERRED_SIZE).addGap(35,
    										35, 35)));
    		portPanel1Layout.setVerticalGroup(portPanel1Layout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addGroup(
    				portPanel1Layout.createSequentialGroup().addContainerGap()
    						.addGroup(
    								portPanel1Layout.createParallelGroup(
    										GroupLayout.Alignment.BASELINE)
    										.addComponent(this.serverPortLabel)
    										.addComponent(this.serverPortTextField,
    												GroupLayout.PREFERRED_SIZE,
    												GroupLayout.DEFAULT_SIZE,
    												GroupLayout.PREFERRED_SIZE))
    						.addContainerGap(GroupLayout.DEFAULT_SIZE,
    								Short.MAX_VALUE)));
    
    		this.destructablesPanel.setBorder(BorderFactory.createEtchedBorder());
    		this.destructablesPanel.setMaximumSize(new Dimension(190, 43));
    		this.destructablesPanel.setMinimumSize(new Dimension(190, 43));
    		this.destructablesPanel.setPreferredSize(new Dimension(190, 43));
    
    		this.generateLabel.setFont(new Font("Tahoma", 0, 12)); // NOI18N
    		this.generateLabel.setText("Generate");
    
    		this.destructablesLabel.setFont(new Font("Tahoma", 0, 12)); // NOI18N
    		this.destructablesLabel.setText("destructables:");
    
    		this.destructablesCheckBox.setText("On/Off");
    		this.destructablesCheckBox.addItemListener(new CheckBoxListener());
    
    		GroupLayout destructablesPanelLayout = new GroupLayout(
    				this.destructablesPanel);
    		this.destructablesPanel.setLayout(destructablesPanelLayout);
    		destructablesPanelLayout
    				.setHorizontalGroup(destructablesPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								destructablesPanelLayout
    										.createSequentialGroup()
    										.addContainerGap()
    										.addGroup(
    												destructablesPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.LEADING)
    														.addComponent(
    																this.generateLabel)
    														.addComponent(
    																this.destructablesLabel))
    										.addPreferredGap(
    												ComponentPlacement.RELATED, 26,
    												Short.MAX_VALUE).addComponent(
    												this.destructablesCheckBox).addGap(
    												14, 14, 14)));
    		destructablesPanelLayout.setVerticalGroup(destructablesPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						destructablesPanelLayout.createSequentialGroup()
    								.addComponent(this.generateLabel).addPreferredGap(
    										ComponentPlacement.RELATED)
    								.addComponent(this.destructablesLabel)).addGroup(
    						destructablesPanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(
    										this.destructablesCheckBox,
    										GroupLayout.DEFAULT_SIZE, 25,
    										Short.MAX_VALUE).addContainerGap()));
    
    		this.serverButton.setFont(new Font("Tahoma", 1, 11)); // NOI18N
    		this.serverButton.setText("Start Server");
    		this.serverButton.addActionListener(new ButtonListener());
    
    		this.networkLogServerCheckBox.setLabel("Network log");
    		this.networkLogServerCheckBox.addItemListener(new CheckBoxListener());
    
    		GroupLayout serverButtonPanelLayout = new GroupLayout(this.serverButtonPanel);
    		this.serverButtonPanel.setLayout(serverButtonPanelLayout);
    		serverButtonPanelLayout.setHorizontalGroup(serverButtonPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						serverButtonPanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(this.serverButton)
    								.addPreferredGap(ComponentPlacement.RELATED)
    								.addComponent(this.networkLogServerCheckBox)
    								.addContainerGap(GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE)));
    		serverButtonPanelLayout
    				.setVerticalGroup(serverButtonPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								serverButtonPanelLayout
    										.createSequentialGroup()
    										.addContainerGap()
    										.addGroup(
    												serverButtonPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.BASELINE)
    														.addComponent(
    																this.serverButton)
    														.addComponent(
    																this.networkLogServerCheckBox))
    										.addContainerGap(16, Short.MAX_VALUE)));
    
    		GroupLayout innerServerPanelLayout = new GroupLayout(this.innerServerPanel);
    		this.innerServerPanel.setLayout(innerServerPanelLayout);
    		innerServerPanelLayout
    				.setHorizontalGroup(innerServerPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								innerServerPanelLayout
    										.createSequentialGroup()
    										.addGroup(
    												innerServerPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.LEADING)
    														.addGroup(
    																innerServerPanelLayout
    																		.createSequentialGroup()
    																		.addContainerGap()
    																		.addComponent(
    																				this.maxPlayersPanel,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				Short.MAX_VALUE))
    														.addGroup(
    																innerServerPanelLayout
    																		.createSequentialGroup()
    																		.addContainerGap()
    																		.addComponent(
    																				this.AISkillPanel,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				Short.MAX_VALUE))
    														.addGroup(
    																innerServerPanelLayout
    																		.createSequentialGroup()
    																		.addContainerGap()
    																		.addComponent(
    																				this.serverPortPanel,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				Short.MAX_VALUE))
    														.addGroup(
    																innerServerPanelLayout
    																		.createSequentialGroup()
    																		.addContainerGap()
    																		.addComponent(
    																				this.destructablesPanel,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				Short.MAX_VALUE))
    														.addComponent(
    																this.serverButtonPanel,
    																GroupLayout.DEFAULT_SIZE,
    																200,
    																Short.MAX_VALUE))
    										.addContainerGap()));
    		innerServerPanelLayout.setVerticalGroup(innerServerPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						GroupLayout.Alignment.TRAILING,
    						innerServerPanelLayout.createSequentialGroup()
    								.addContainerGap().addComponent(
    										this.maxPlayersPanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addPreferredGap(
    										ComponentPlacement.RELATED,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addComponent(
    										this.AISkillPanel, GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addPreferredGap(
    										ComponentPlacement.RELATED)
    								.addComponent(this.serverPortPanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addPreferredGap(
    										ComponentPlacement.RELATED)
    								.addComponent(this.destructablesPanel,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE).addPreferredGap(
    										ComponentPlacement.RELATED)
    								.addComponent(this.serverButtonPanel,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)));
    
    		GroupLayout ServerPanelLayout = new GroupLayout(this.ServerPanel);
    		this.ServerPanel.setLayout(ServerPanelLayout);
    		ServerPanelLayout
    				.setHorizontalGroup(ServerPanelLayout
    						.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addGroup(
    								ServerPanelLayout
    										.createSequentialGroup()
    										.addGroup(
    												ServerPanelLayout
    														.createParallelGroup(
    																GroupLayout.Alignment.LEADING)
    														.addGroup(
    																ServerPanelLayout
    																		.createSequentialGroup()
    																		.addGap(
    																				88,
    																				88,
    																				88)
    																		.addComponent(
    																				this.serverTextField))
    														.addGroup(
    																ServerPanelLayout
    																		.createSequentialGroup()
    																		.addContainerGap()
    																		.addComponent(
    																				this.innerServerPanel,
    																				GroupLayout.PREFERRED_SIZE,
    																				GroupLayout.DEFAULT_SIZE,
    																				GroupLayout.PREFERRED_SIZE)))
    										.addContainerGap(
    												GroupLayout.DEFAULT_SIZE,
    												Short.MAX_VALUE)));
    		ServerPanelLayout.setVerticalGroup(ServerPanelLayout
    				.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
    						ServerPanelLayout.createSequentialGroup()
    								.addContainerGap()
    								.addComponent(this.serverTextField).addGap(18, 18,
    										18).addComponent(this.innerServerPanel,
    										GroupLayout.PREFERRED_SIZE,
    										GroupLayout.DEFAULT_SIZE,
    										GroupLayout.PREFERRED_SIZE)
    								.addContainerGap(GroupLayout.DEFAULT_SIZE,
    										Short.MAX_VALUE)));
    
    		GroupLayout layout = new GroupLayout(getContentPane());
    		getContentPane().setLayout(layout);
    		layout.setHorizontalGroup(layout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addGroup(
    				layout.createSequentialGroup().addComponent(this.ClientPanel,
    						GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
    						GroupLayout.PREFERRED_SIZE).addPreferredGap(
    						ComponentPlacement.RELATED).addComponent(this.ServerPanel,
    						GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
    						GroupLayout.PREFERRED_SIZE)));
    		layout.setVerticalGroup(layout.createParallelGroup(
    				GroupLayout.Alignment.LEADING).addComponent(this.ClientPanel,
    				GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
    				Short.MAX_VALUE).addComponent(this.ServerPanel, 0, 322,
    				Short.MAX_VALUE));
    
    		pack();
    	}
    
    	private class ButtonListener implements ActionListener {
    
    		@Override
    		public void actionPerformed(ActionEvent e) {
    
    			String cmd = e.getActionCommand().toLowerCase().trim();
    			if (cmd.equals("start client")) {
    				Launcher.startGame();
    				networkLogClientCheckBox.setEnabled(false);
    				networkLogServerCheckBox.setEnabled(false);
    			} else if (cmd.equals("start server")) {
    				Launcher.startServer();
    				networkLogClientCheckBox.setEnabled(false);
    				networkLogServerCheckBox.setEnabled(false);
    			}
    		}
    
    	}
    
    	private class CheckBoxListener implements ItemListener {
    
    		public void itemStateChanged(ItemEvent e) {
    
    			if (e.getSource() == aiDebugCheckBox) {
    				if (aiDebugCheckBox.isSelected()) {
    					Const.AI_DEBUG = true;
    				} else {
    					Const.AI_DEBUG = false;
    				}
    			}
    
    			if (e.getSource() == networkLogClientCheckBox) {
    				if (networkLogClientCheckBox.isSelected()) {
    					Const.LOG_NETWORK_TRAFFIC = true;
    					networkLogServerCheckBox.setSelected(true);
    				} else {
    					Const.LOG_NETWORK_TRAFFIC = false;
    					networkLogServerCheckBox.setSelected(false);
    				}
    			}
    
    			if (e.getSource() == networkLogServerCheckBox) {
    				if (networkLogServerCheckBox.isSelected()) {
    					Const.LOG_NETWORK_TRAFFIC = true;
    					networkLogClientCheckBox.setSelected(true);
    				} else {
    					Const.LOG_NETWORK_TRAFFIC = false;
    					networkLogClientCheckBox.setSelected(false);
    				}
    			}
    			
    			if (e.getSource() == destructablesCheckBox){
    				if(destructablesCheckBox.isSelected()){
    					Const.GENERATE_CRATES = true;
    					Const.GENERATE_POWERUPS = true;
    				}else{
    					Const.GENERATE_CRATES = false;
    					Const.GENERATE_POWERUPS = false;
    				}
    			}
    		}
    	}
    
    	@Override
    	public void run() {
    		// TODO Auto-generated method stub
    
    	}
    
    	public String getIP() {
    		return this.IPcurrent;
    	}
    
    	public int getClientPort() {
    		return Integer.parseInt(this.clientPortTextField.getText());
    	}
    
    	public int getServerPort() {
    		return Integer.parseInt(this.serverPortTextField.getText());
    	}
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    I get an Illegal State Exception
    Please copy and paste full text of error message here. Also find the source statement referred to in the error message and post the statements around there.

    It looks like most of your code was generated by an IDE. Ugh!

  3. #3
    eckt is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi Norm,

    As mentioned above, yes the code has been generated in Netbeans and then edited. The explanation is also above.
    Here is the full error message:
    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JPanel[,0,0,0x0,invalid,layout=javax.swing.GroupLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.LineBorder@4b222f,flags=9,maximumSize=,minimumSize=,preferredSize=] is not attached to a horizontal group
    	at javax.swing.GroupLayout.checkComponents(Unknown Source)
    	at javax.swing.GroupLayout.prepare(Unknown Source)
    	at javax.swing.GroupLayout.layoutContainer(Unknown Source)
    	at java.awt.Container.layout(Unknown Source)
    	at java.awt.Container.doLayout(Unknown Source)
    	at java.awt.Container.validateTree(Unknown Source)
    	at java.awt.Container.validateTree(Unknown Source)
    	at java.awt.Container.validateTree(Unknown Source)
    	at java.awt.Container.validate(Unknown Source)
    	at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
    	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default

    The error message says
    JPanel ... is not attached to a horizontal group
    Some misuse of a layout manager.
    It looks like netbeans built something that doesn't work in your new IDE.
    Can you remove the GUI stuff from netbeans and rebuilt it in the new IDE?

    I added the missing classes as dummys and am able to compile and execute (up to a point) the program.
    I am not using an IDE. I used javac from jdk 1.6.0_02
    Running: D:\Java\jdk1.6.0_02\bin\javac.exe -Xlint -g -deprecation -classpath D:\JavaDevelopment\;. NetBeans_GUI.java
    I executed it with java from jre 1.6.0_10:
    Running: D:\Java\jre6_10\bin\java.exe -classpath D:\JavaDevelopment;. -Xmx512M NetBeans_GUI
    After trying it a few times, I was able to get the same exception as you do.
    Did you notice the small frame that shows for an instance before the full one is formatted?
    That's because the setVisible() is done before the formatting is done.
    If you move the setVisible() to the end of the method, there is no more flashing small frame and there hasn't been any exceptions.
    Last edited by Norm; 06-13-2010 at 10:28 PM. Reason: Found source change

  5. #5
    eckt is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default

    Norm; you are my hero!
    Thank you SO much!
    Have a great day!
    Best regards,
    Emma

Similar Threads

  1. Replies: 5
    Last Post: 03-17-2011, 02:26 PM
  2. Replies: 2
    Last Post: 12-14-2009, 01:46 AM
  3. Replies: 13
    Last Post: 09-07-2009, 04:32 PM
  4. Replies: 2
    Last Post: 05-28-2009, 05:09 PM
  5. Replies: 2
    Last Post: 09-18-2008, 07:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •