Lejos PC coding error

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, 99jonathan, imaqine

Lejos PC coding error

Postby bczm8703 » Mon Oct 22, 2012 5:42 am

hi.. i am trying to make game involving the NXT and PC via Bluetooth connection... the connection and everything is ok... the stage i am in now is i am trying to increment the score when i pressed btn A and draw a image and decrease score when pressed btn B.. the score increment and decrment is correct but the image doesn't seem to come out.. the image directory, path and filename have all being thriple checked and they are correct..

i am using Win 7 OS with Ecplise

Code: Select all
public class ButtonHandler implements ActionListener{
          public void actionPerformed(ActionEvent e){
           if(e.getSource()==b[0]){//letter A
              b1 = true;
              score++;
              statusScore.setText("Score: "+score);
             
             }
          else if(e.getSource()==b[1]){//letter B
             b1=false; //initialize to true
             repaint();
             wrong++; // initialize to 0
             score--;
             
             statusScore.setText("Score: "+score);
            
             }
}

public void hangman(Graphics g, int mistake){
       
       //image = new ImageIcon("bin/Images/"+mistake+"gif").getImage();
       System.out.println("Mistake: "+mistake);
       image = new ImageIcon("bin/Images/hangman"+mistake+".gif").getImage();
       g.drawImage(image,70,60,null);
      repaint();
       
       
   }
   
    public void paint(Graphics g) {
       super.paint(g);
       if(!b1){
          b1=true;
          hangman(g,wrong);   
       }
       
    }


bczm8703
New User
 
Posts: 13
Joined: Fri Sep 21, 2012 7:58 am

Re: Lejos PC coding error

Postby gloomyandy » Mon Oct 22, 2012 2:03 pm

I'm not sure I understand exactly what it is you are trying to do here. Is this code running on the PC? Are you expecting the images to appear on the NXT, or on the PC screen? Are you sure that the path is correct when being used relative to the working directory of your running program. I would try using a full absolute path name to see if that makes things work. Are you getting any sort of exception from the code? Oh and it is probably not a good idea to have that call to repaint in there.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Lejos PC coding error

Postby bczm8703 » Mon Oct 22, 2012 2:14 pm

The code is run on the pc.... The flow of the program is like a hangman game... The nxt generate a word from a predefined word bank... Then when the nxt send the start signal... The game will start.. When a key is being press, the pc will send that corresponding letter to nxt for checking if it contain in the selected word.. If it isn't the nxt will send wrong and the picture will be drawn on the pc.... The current testing phase pressing button A will symbolise a correct response while button B symbolise a wrong answer and the pc is suppose to draw the image...

Using a relative path is because the project folder might change location or even tested on a different pc...
bczm8703
New User
 
Posts: 13
Joined: Fri Sep 21, 2012 7:58 am

Re: Lejos PC coding error

Postby gloomyandy » Mon Oct 22, 2012 8:00 pm

I wasn't suggesting using an absolute path for ever, just to ensure that it is not a problem with the relative path that you are currently using. Other than that, this is really a general Java swing problem not NXT specific, so you may get a better answer on a more general Java forum.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff