Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    26
    Rep Power
    0

    Default OMG GUI COMPILER probs

    hi PLEASE LOOK AT THE CODE (LIST ERRORS FIRST GIVEN BY COMILER THEN CODE)



    errors
    ./MyDrawPanel.java:1: cannot find symbol
    symbol: class JPanel
    class MyDrawPanel extends JPanel
    ^
    ./MyDrawPanel.java:3: cannot find symbol
    symbol : class Graphics
    location: class MyDrawPanel
    public void paintComponent(Graphics g)
    ^
    SimpleGui3C.java:28: cannot find symbol
    symbol : method add(java.lang.String,MyDrawPanel)
    location: class java.awt.Container
    frame.getContentPane().add(BorderLayout.CENTER, drawPanel);
    ^
    ./MyDrawPanel.java:11: cannot find symbol
    symbol : variable Color
    location: class MyDrawPanel
    g.setColor(Color.red);
    ^
    ./MyDrawPanel.java:11: int cannot be dereferenced
    g.setColor(Color.red);
    ^
    ./MyDrawPanel.java:12: int cannot be dereferenced
    g.fillOval(10,10,40,40);
    ^
    6 errors


    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    
    class SimpleGui3C  implements ActionListener
    {
    
    JFrame frame;
    
    public static void main (String[] args)
    {
    SimpleGui3C gui = new SimpleGui3C();
    gui.go();
    }
    
    public void go()
    {
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    JButton button = new JButton("Change colors");
    button.addActionListener(this);
    
    MyDrawPanel drawPanel = new MyDrawPanel();
    
    frame.getContentPane().add(BorderLayout.SOUTH, button);
    frame.getContentPane().add(BorderLayout.CENTER, drawPanel);
    frame.setSize(300,300);
    frame.setVisible(true);
    
    }
    public void actionPerformed(ActionEvent event)
    {
    frame.repaint();
    }
    }

    Java Code:
    class MyDrawPanel extends JPanel
    {
    public void paintComponent(Graphics g)
    {
    
    
    int r = (int) (Math.random() * 255);
    int g = (int) (Math.random() * 255);
    int b = (int) (Math.random() * 255);
    Color boy = new Color(r, g, b);
    g.setColor(boy);
    g.fillOval(10,10,40,40);
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If your code has the proper imports, it should compile, except for here:

    Java Code:
    public void paintComponent(Graphics g)
    {
       int r = (int) (Math.random() * 255);
       int g = (int) (Math.random() * 255);  // *** variable naming clash
       int b = (int) (Math.random() * 255);
       Color boy = new Color(r, g, b);
       g.setColor(boy);
       g.fillOval(10,10,40,40);
    }
    your method has two g variables, one a parameter and one an int variable, and this will never work. You'll have to name one differently.

  3. #3
    Join Date
    Nov 2009
    Posts
    26
    Rep Power
    0

    Default

    thanks a lot.... i didn't even notice that....

  4. #4
    Join Date
    Nov 2009
    Posts
    26
    Rep Power
    0

    Default

    still not working.... are my imports wrong...

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. compiler,JIT compiler & interpreter
    By gamilah in forum New To Java
    Replies: 4
    Last Post: 11-04-2008, 01:32 AM
  2. Replies: 6
    Last Post: 10-17-2008, 07:11 PM
  3. probs
    By amith in forum Java 2D
    Replies: 1
    Last Post: 06-29-2008, 10:13 PM
  4. A few java probs
    By Mezzie in forum New To Java
    Replies: 4
    Last Post: 06-11-2008, 08:59 AM
  5. Asking for the compiler
    By fernando in forum Other IDEs
    Replies: 1
    Last Post: 08-06-2007, 10:04 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
  •