Results 1 to 3 of 3
  1. #1
    sam.jj12 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Cannot find symbol

    I am a newbie to swings..please help me out in solving this..
    I need to change the colors of circle each time the button is being clicked
    I have two classes namely Gui4.java and MyDrawPanel.java ..I am trying to create an object for MyDrawPanel in Gui4 and use the getContentpane() method.I am posting t codes of both program.I am executing thro cmd prompt.

    //Gui4.java
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;

    public class Gui4 implements ActionListener
    {
    JFrame frame;
    public static void main(String[] args)
    {
    Gui4 gui = new Gui4();
    gui.go();

    }
    public void go()
    {
    frame = new JFrame (" change colors");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    JButton button = new JButton();
    button.addActionListener(this);

    MyDrawPanel drawpanel = new MyDrawpanel();

    frame.getContentPane().add(BorderLayout.SOUTH,butt on);

    frame.getContentPane().add(BorderLayout.CENTER,dra wpanel);

    frame.setSize(300,300);
    frame.setVisible(true);
    }
    public void actionPerformed(ActionEvent event)
    {
    frame.repaint();
    }
    }

    //MyDrawPanel.java

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;

    class MyDrawPanel extends JPanel
    {


    public void paintComponent(Graphics g)
    {
    g.fillRect(0,0,this.getWidth(),this.getHeight());

    int red = (int) (Math.random()*255);
    int green = (int) (Math.random()*255);
    int blue = (int) (Math.random()*255);

    Color random = new Color(red,green,blue);

    g.setColor(random);
    g.fillOval(70,70,100,100);
    }
    }

    And I am getting the error as follows :

    D:\jp>javac Gui4.java
    Gui4.java:21: error: cannot find symbol
    MyDrawPanel drawpanel = new MyDrawpanel();
    ^
    symbol: class MyDrawpanel
    location: class Gui4
    1 error


    Please help me out in getting output.

    Thanks,
    sam

  2. #2
    sam.jj12 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Cannot find symbol

    sorry to all...I found the mistake..
    I have used small letter while creating the object...
    Plez forgive my mistake...
    Thanks again ,
    Sam

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Cannot find symbol

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Cannot Find Symbol
    By Concacaf in forum New To Java
    Replies: 5
    Last Post: 05-09-2011, 01:47 PM
  2. Cannot find symbol
    By Johanis in forum New To Java
    Replies: 18
    Last Post: 11-09-2010, 09:34 PM
  3. Still cannot find symbol!
    By Johanis in forum New To Java
    Replies: 1
    Last Post: 11-04-2010, 05:32 PM
  4. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 09:30 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
  •