Close

Results 1 to 13 of 13

Thread: Java; anyone?

  1. #1
    DF Super Moderator Rick Sanchez's Avatar
    Join Date
    Dec 2004
    Location
    Shoney's
    Posts
    3,811
    Thanks
    1,326
    Thanked:        366
    Karma Level
    408

    Help Java; anyone?

    Hi guys,

    I've hit a brickwall and cannot work out my error, the error code is:

    The type KeyControlledRobot is never used locally. KeyControlledRobot is in a external jar that has been linked.


    I'm new to Java and your help is much appreciated.

    Thank you

  2. #2
    DF VIP Member Mobius's Avatar
    Join Date
    Jun 2001
    Location
    The Internet
    Posts
    170
    Thanks
    3
    Thanked:        9
    Karma Level
    285

    Default Re: Java; anyone?

    Quote Originally Posted by hilljd00 View Post
    Hi guys,

    I've hit a brickwall and cannot work out my error, the error code is:

    The type KeyControlledRobot is never used locally. KeyControlledRobot is in a external jar that has been linked.


    I'm new to Java and your help is much appreciated.

    Thank you
    Can you give a bit more detail, maybe show the code?

    Is this an error or a warning?

  3. #3
    DF VIP Member ap0c's Avatar
    Join Date
    Sep 2007
    Location
    UK
    Posts
    937
    Thanks
    132
    Thanked:        38
    Karma Level
    260

    Default Re: Java; anyone?

    Sounds like you need to look into java extends

    take a look at this thread:

    http://stackoverflow.com/questions/8...ther-java-file

  4. #4
    DF Super Moderator Rick Sanchez's Avatar
    Join Date
    Dec 2004
    Location
    Shoney's
    Posts
    3,811
    Thanks
    1,326
    Thanked:        366
    Karma Level
    408

    Default Re: Java; anyone?

    See attached. I've deleted the comments and the errors changed.

  5. #5
    DF VIP Member Mobius's Avatar
    Join Date
    Jun 2001
    Location
    The Internet
    Posts
    170
    Thanks
    3
    Thanked:        9
    Karma Level
    285

    Default Re: Java; anyone?

    Quote Originally Posted by hilljd00 View Post
    See attached. I've deleted the comments and the errors changed.

    Ok, What is it you're trying to do? You seem to have started out defining a Map class going by the .java filename, then tried to declare another public class inside its main method which isn't alowed. If you want to define KeyControlledRobot as a public class it needs to be in its own .java file.

  6. #6
    DF Super Moderator Rick Sanchez's Avatar
    Join Date
    Dec 2004
    Location
    Shoney's
    Posts
    3,811
    Thanks
    1,326
    Thanked:        366
    Karma Level
    408

    Default Re: Java; anyone?

    I am basically trying to create a "tank" that I can drive around with the up,down, left and right keys but can also get the tank to shoot using the space bar or similar keys.

    I have the tank sprite ready but I am struggling with the rest lol.

  7. #7
    DF VIP Member Mobius's Avatar
    Join Date
    Jun 2001
    Location
    The Internet
    Posts
    170
    Thanks
    3
    Thanked:        9
    Karma Level
    285

    Default Re: Java; anyone?

    Without going into specific design details, you can define KeyControlledRobot as a seperate public class in a seperate KeyControlledRobot.java. Alternatively if you only want to use KeyControlledRobot inside the map class you can define it as a private class in Map.java. You would do the inside outside the Map class but not inside a method like you have now.

    HTH

  8. #8
    DF Super Moderator Rick Sanchez's Avatar
    Join Date
    Dec 2004
    Location
    Shoney's
    Posts
    3,811
    Thanks
    1,326
    Thanked:        366
    Karma Level
    408

    Default Re: Java; anyone?

    Yay I got it working

    Now I just need to make an automated version that can drive itself, detect walls (boolean) and automatically shoot at other tanks!

    I know I need a while loop for this but is there anything else needed?

    I'm re-writing this

    Code:
    public void keyPressed(KeyEvent e)
        {
            if (e.getKeyCode() == KeyEvent.VK_RIGHT)  
            {
                this.turnRight();
            }
            else if    (e.getKeyCode() == KeyEvent.VK_LEFT)
            {
                this.turnLeft();
            }
            else if (e.getKeyCode() == KeyEvent.VK_DOWN)
            {
                this.reverseGear();
                this.accelerate();
            }
            else if 
            (e.getKeyCode() == KeyEvent.VK_UP) 
            {
                this.forwardGear();
                this.accelerate();
            }
            
            if (e.getKeyCode() ==  KeyEvent.VK_ALT)
            {
                this.fire();
            }
    Any advice would be appreciated

  9. #9
    DF VIP Member blacksheep's Avatar
    Join Date
    Jun 2006
    Location
    Manchester
    Posts
    3,877
    Thanks
    87
    Thanked:        265
    Karma Level
    546

    Default Re: Java; anyone?

    I've seen these sort of things before used in education/code competition type things (presuming this is a robot battle arena style idea where you get points for shooting the other robots) - do you have the api you're rewriting against to hand?

    I'd separate the shoot/move out into two separate functions then in the main method you can just have a while loop that calls these and then maybe has a sleep in it. You can then refine the move/shoot as needed from random drive about to a grid search or if there is some kind of radar/detection of other objects etc.

  10. #10
    DF Super Moderator Rick Sanchez's Avatar
    Join Date
    Dec 2004
    Location
    Shoney's
    Posts
    3,811
    Thanks
    1,326
    Thanked:        366
    Karma Level
    408

    Default Re: Java; anyone?

    Exactly that. I am going to use a while loop to do this I think.

    What I have so far and stuff commented out until I get the automation working properly.
    Last edited by Rick Sanchez; 28th November 2012 at 10:19 PM.

  11. #11
    DF VIP Member blacksheep's Avatar
    Join Date
    Jun 2006
    Location
    Manchester
    Posts
    3,877
    Thanks
    87
    Thanked:        265
    Karma Level
    546

    Default Re: Java; anyone?

    If you're not going to use keys to control it you probably don't need the key listener interface nor register the object as a key listener.

    You really don't want the while loop in the constructor - either have it in the main method or create another function like:

    Private void run()
    {
    While(true)
    {
    Move();
    Shoot();
    }
    }

    Then in the main method you just have robbie.run().
    Id
    Also remove your URL from public posts

    Thanks to blacksheep

    Rick Sanchez (28th November 2012)  


  12. #12
    DF VIP Member blacksheep's Avatar
    Join Date
    Jun 2006
    Location
    Manchester
    Posts
    3,877
    Thanks
    87
    Thanked:        265
    Karma Level
    546

    Default Re: Java; anyone?

    Sorry for the crappy formatting/capitalisation I'm typing this on a mobile device.

    Thanks to blacksheep

    Rick Sanchez (20th November 2012)  


  13. #13
    DF Super Moderator Rick Sanchez's Avatar
    Join Date
    Dec 2004
    Location
    Shoney's
    Posts
    3,811
    Thanks
    1,326
    Thanked:        366
    Karma Level
    408

    Default Re: Java; anyone?

    Sorted
    Last edited by Rick Sanchez; 28th November 2012 at 09:40 PM.

Similar Threads

  1. J2ME / JBlend Java on Sharp GX10 ???
    By hummmm in forum Programming
    Replies: 0
    Last Post: 25th November 2002, 01:45 AM
  2. Java Popup's :()
    By Dragoncity in forum The Dog and Duck
    Replies: 0
    Last Post: 7th October 2002, 04:16 PM
  3. Java console??
    By Jaffa in forum PC Problems
    Replies: 3
    Last Post: 26th September 2002, 02:14 AM
  4. Java Idea?
    By Roo in forum Unlocking Questions & Solutions
    Replies: 0
    Last Post: 8th September 2002, 06:55 PM

Social Networking Bookmarks

Posting Permissions

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