There's something strange about it.
In my InitGui() methode he thinks my game object still has null values but in my actionperformed method I can use the game object.![]()
![]()
Code:public class FightJPanel extends javax.swing.JPanel { private TestFrame main; private HeroQuest game; private JLabel jLabelHero; private JButton jButtonDice; public FightJPanel(TestFrame frame, HeroQuest hero) { super(); main = frame; game = hero; initGui(); } private void initGui() { game.getType(); // THIS DOESN'T WORK, IT GIVES A NULL //POINTEREXCEPTION try { //SOME LAYOUT STUFF WAS HERE { jButtonDice = new JButton(); this.add(jButtonDice, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jButtonDice.setPreferredSize(new java.awt.Dimension(91, 55)); jButtonDice.setText("roll dice"); jButtonDice.setBorder(new LineBorder(new java.awt.Color(0,0,0), 4, true)); jButtonDice.setBackground(new java.awt.Color(255,255,255)); jButtonDice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButtonDiceActionPerformed(evt); } }); } { jLabelHero = new JLabel(); this.add(jLabelHero, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); //jLabelHero.setText(game.getActionPoints())> THIS //DOESNT WORK ASWELL > NULLPOINTER EXCEPTION; jLabelHero.setOpaque(true); jLabelHero.setBackground(Color.WHITE); jLabelHero.setForeground(Color.BLACK); jLabelHero.setPreferredSize(new java.awt.Dimension(58, 20)); } } catch (Exception e) { e.printStackTrace(); } } private void jButtonDiceActionPerformed(ActionEvent evt) { jButtonDice.setText(game.getType());//GUESS WHAT IT WORKS HERE } }


Reply With Quote


Bookmarks