Results 1 to 6 of 6
  1. #1
    Naphoria is offline Member
    Join Date
    Jan 2012
    Posts
    6
    Rep Power
    0

    Default My Java Robot Obstacle drawing

    This is the code for the obstacle drawing class for the java robot (it has distance and touch sensors for finding obstacles in an arena):

    import london.*;

    public class DrawObstacles {

    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }
    });
    }

    private static void createAndShowGUI() {
    System.out.println("Created GUI on EDT? "+
    SwingUtilities.isEventDispatchThread());
    JFrame f = new JFrame("Swing Paint Demo");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new MyPanel());
    f.pack();
    f.setVisible(true);
    }
    }

    class MyPanel extends JPanel {

    private int squareX = 50;
    private int squareY = 50;
    private int squareW = 20;
    private int squareH = 20;

    public MyPanel() {

    setBorder(BorderFactory.createLineBorder(Color.bla ck));

    addSensorListener(new SensorAdapter() {
    public void sensorTriggered(SensorEvent e) {
    moveSquare(e.getX(),e.getY());
    }
    });

    addRobotMotionListener(new RobotAdapter() {
    public void RobotMoved(RobotEvent e) {
    moveSquare(e.getX(),e.getY());
    }
    });

    }

    private void moveSquare(int x, int y) {
    int OFFSET = 1;
    if ((squareX!=x) || (squareY!=y)) {
    repaint(squareX,squareY,squareW+OFFSET,squareH+OFF SET);
    squareX=x;
    squareY=y;
    repaint(squareX,squareY,squareW+OFFSET,squareH+OFF SET);
    }
    }


    public Dimension getPreferredSize() {
    return new Dimension(250,200);
    }

    protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawString("This is my custom Panel!",10,20);
    g.setColor(Color.RED);
    g.fillRect(squareX,squareY,squareW,squareH);
    g.setColor(Color.BLACK);
    g.drawRect(squareX,squareY,squareW,squareH);
    }
    }

    The "london" package contains a class called EasyGraphics which draws on the javax.swing.JFrame

    There is a lot of problems with this code, so if anyone could help me, that would be great, thank you!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,964
    Rep Power
    8

    Default Re: My Java Robot Obstacle drawing

    What are the problems with the code? I suggest you narrow each one down to an SSCCE that demonstrates just that problem, and post it here with a specific question including the exact error message or strange behavior. Don't forget the code tags.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Naphoria is offline Member
    Join Date
    Jan 2012
    Posts
    6
    Rep Power
    0

    Default Re: My Java Robot Obstacle drawing

    I dont really have time, but these are the errors:



    DrawObstacles.java:24: cannot find symbol
    symbol: class JPanel
    class MyPanel extends JPanel {
    ^
    DrawObstacles.java:60: cannot find symbol
    symbol : class Dimension
    location: class MyPanel
    public Dimension getPreferredSize() {
    ^
    DrawObstacles.java:64: cannot find symbol
    symbol : class Graphics
    location: class MyPanel
    protected void paintComponent(Graphics g) {
    ^
    DrawObstacles.java:6: cannot find symbol
    symbol : variable SwingUtilities
    location: class DrawObstacles
    SwingUtilities.invokeLater(new Runnable() {
    ^
    DrawObstacles.java:15: cannot find symbol
    symbol : variable SwingUtilities
    location: class DrawObstacles
    SwingUtilities.isEventDispatchThread());
    ^
    DrawObstacles.java:16: cannot find symbol
    symbol : class JFrame
    location: class DrawObstacles
    JFrame f = new JFrame("Swing Paint Demo");
    ^
    DrawObstacles.java:16: cannot find symbol
    symbol : class JFrame
    location: class DrawObstacles
    JFrame f = new JFrame("Swing Paint Demo");
    ^
    DrawObstacles.java:17: cannot find symbol
    symbol : variable JFrame
    location: class DrawObstacles
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ^
    DrawObstacles.java:33: cannot find symbol
    symbol : variable Color
    location: class MyPanel
    setBorder(BorderFactory.createLineBorder(Color.bla ck));
    ^
    DrawObstacles.java:33: cannot find symbol
    symbol : variable BorderFactory
    location: class MyPanel
    setBorder(BorderFactory.createLineBorder(Color.bla ck));
    ^
    DrawObstacles.java:35: cannot find symbol
    symbol : class SensorAdapter
    location: class MyPanel
    addSensorListener(new SensorAdapter() {
    ^
    DrawObstacles.java:41: cannot find symbol
    symbol : class RobotAdapter
    location: class MyPanel
    addRobotMotionListener(new RobotAdapter() {
    ^
    DrawObstacles.java:52: cannot find symbol
    symbol : method repaint(int,int,int,int)
    location: class MyPanel
    repaint(squareX,squareY,squareW+OFFSET,squareH+OFF SET);
    ^
    DrawObstacles.java:55: cannot find symbol
    symbol : method repaint(int,int,int,int)
    location: class MyPanel
    repaint(squareX,squareY,squareW+OFFSET,squareH+OFF SET);
    ^
    DrawObstacles.java:61: cannot find symbol
    symbol : class Dimension
    location: class MyPanel
    return new Dimension(250,200);
    ^
    DrawObstacles.java:65: cannot find symbol
    symbol : variable super
    location: class MyPanel
    super.paintComponent(g);
    ^
    DrawObstacles.java:67: cannot find symbol
    symbol : variable Color
    location: class MyPanel
    g.setColor(Color.RED);
    ^
    DrawObstacles.java:69: cannot find symbol
    symbol : variable Color
    location: class MyPanel
    g.setColor(Color.BLACK);
    ^
    18 errors

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,964
    Rep Power
    8

    Default Re: My Java Robot Obstacle drawing

    If *you* don't have time to fix *your* errors, why do you presume that *we* do? We're doing this voluntarily, for free, in our spare time. If you can't put any time into asking a question, why expect others to put time into answering it?

    Are you sure you're importing everything you need?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Naphoria is offline Member
    Join Date
    Jan 2012
    Posts
    6
    Rep Power
    0

    Default Re: My Java Robot Obstacle drawing

    Sorry I appreciate this I really do, (i would actually pay you if it could be done quicker though!) Is that what "cannot find symbol" means, because I notice that that is the only error?!

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,964
    Rep Power
    8

    Default Re: My Java Robot Obstacle drawing

    Quote Originally Posted by Naphoria View Post
    Sorry I appreciate this I really do, (i would actually pay you if it could be done quicker though!) Is that what "cannot find symbol" means, because I notice that that is the only error?!
    It could mean a couple things. It means that the compiler is trying to figure out what a word that you're using means, but it can't find a declaration of it anywhere. For things like variables, it usually means you haven't declared that variable in that scope. For things like classes, it usually means that you haven't imported it correctly. For things like methods, it usually is a symptom of not being able to find the class- it doesn't know what the class is, so it doesn't know which methods the class contains, so it can't find that method. Check your imports.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 3
    Last Post: 12-03-2011, 01:38 PM
  2. drawing in java
    By Ike in forum New To Java
    Replies: 2
    Last Post: 11-07-2011, 06:39 PM
  3. Replies: 2
    Last Post: 05-22-2011, 08:56 AM
  4. Help with Java Robot and Runtime Class
    By Rmond1254 in forum New To Java
    Replies: 1
    Last Post: 02-18-2009, 06:33 AM
  5. Java Robot commands not working
    By CoolLove in forum Java Applets
    Replies: 2
    Last Post: 01-13-2009, 02:58 PM

Posting Permissions

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