Like if there's a ghost in my program :) - New to java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Like if there's a ghost in my program :) - New to java

  1. #1
    Join Date
    Apr 2007
    Posts
    1

    Like if there's a ghost in my program :) - Objects are created later

    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 
    		
    		
    		
    	}
    	
    	
    
    }
    Last edited by Leavemealone; 04-30-2007 at 09:51 AM. Reason: Not clear enough

  2. #2
    Join Date
    Apr 2007
    Location
    Busano
    Posts
    4
    Are you sure that hero parameter passed to the constructor of FightJPanel is not null?

Similar Threads

  1. Java book
    By Lou in forum Java
    Replies: 9
    Last Post: 09-19-2007, 05:58 AM
  2. Help! Simple Java Program.
    By SlickWilly440 in forum Java
    Replies: 2
    Last Post: 01-28-2006, 09:17 PM
  3. DevX does seem one sideded
    By Rob Abbe in forum Talk to the Editors
    Replies: 44
    Last Post: 01-13-2003, 02:57 PM
  4. Has Sun Given Up on the Desktop?
    By Lori Piquet in forum Talk to the Editors
    Replies: 114
    Last Post: 10-10-2002, 06:01 AM
  5. .NET vs. Enterprise Java: Who's Got Better Security?
    By Glen Kunene in forum Talk to the Editors
    Replies: 17
    Last Post: 03-23-2002, 12:43 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center