Cannot resolve symbol java.awt.graphics

// DrawRectangleDemo.java
import java.awt.*;
import java.lang.Object;
import java.applet.Applet;
public class DrawRectangleDemo extends Applet
     public void paint (Graphics g)
          // Get the height and width of the applet's drawing surface.
          int width = getSize ().width;
          int height = getSize ().height;
          int rectWidth = (width-50)/3;
          int rectHeight = (height-70)/2;
          int x = 5;
          int y = 5;
          g.drawRect (x, y, rectWidth, rectHeight);
          g.drawString ("drawRect", x, rectHeight + 30);
          x += rectWidth + 20;
          g.fillRect (x, y, rectWidth, rectHeight);
          // Calculate a border area with each side equal tp 25% of
          // the rectangle's width.
          int border = (int) (rectWidth * 0.25);
          // Clear 50% of the filled rectangle.
          g.clearRect (x + border, y + border,
                         rectWidth - 2 * border, rectHeight - 2 * border);
          g.drawString ("fillRect/clearRect", x, rectHeight + 30);
          x += rectWidth + 20;
          g.drawRoundRect (x, y, rectWidth, rectHeight, 15, 15);
          g.drawString ("drawRoundRect", x, rectHeight + 30);
          x=5;
          y += rectHeight + 40;
          g.setColor (Color.yellow);
          for (int i = 0; i < 4; i++)
               g.draw3DRect (x + i * 2, y + i * 2,
                                   rectWidth - i * 4, rectHeight - i * 4, false);
          g.setColor (Color.black);
          g.drawString ("draw3DRect", x, y, + rectHeight + 25);
          x += rectWidth + 20;
          g.setColor (Color.yellow);
          g.fill3DRect (x, y, rectWidth, rectHeight, true);
          g.setColor (Color.black);
          g.drawString ("fill3DRect", x, y, + rectHeight + 25);
Help me with this codes. I typed correctly but there still errors.
--------------------Configuration: JDK version 1.3.1 <Default>--------------------
D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:56: cannot resolve symbol
symbol : method drawString (java.lang.String,int,int,int)
location: class java.awt.Graphics
          g.drawString ("draw3DRect", x, y, + rectHeight + 25);
^
D:\Program Files\Xinox Software\JCreator LE\MyProjects\DrawRectangleDemo.java:64: cannot resolve symbol
symbol : method drawString (java.lang.String,int,int,int)
location: class java.awt.Graphics
          g.drawString ("fill3DRect", x, y, + rectHeight + 25);
^
2 errors
Process completed.
-------------------------------------------------------------------------------------------------------------------------------

cannot resolve symbol
symbol : method drawString (java.lang.String,int,int,int)
This is telling you that you are trying to invoke the drawString() method with 4 parameters: String, int, int, int
If you look at the API the drawString() method need 3 parameters: String, int, int - so you have an extra int
location: class java.awt.Graphics
g.drawString ("draw3DRect", x, y, + rectHeight + 25);
Now is you look at your code you will find that you have 3 ',' in you method call. (I don't think you want the ',' after the y.

Similar Messages

  • 3 graphic errors- Cannot resolve Symbols

    I am looking for help to resolve 3 errors that I don't understand and I am hoping someone can take the time to point me in the right directions.
    The errors occur while setting the forground color, trying to repaint and trying to draw a rectangle.
    Here are the errors from the compiler:
    Worm.java [42:1] cannot resolve symbol
    symbol : method setForeground (java.awt.Color)
    location: class Worm
    setForeground(Color.RED);
    ^
    Worm.java [49:1] cannot resolve symbol
    symbol : method repaint ()
    location: class Worm
    repaint();
    ^
    Worm.java [56:1] cannot resolve symbol
    symbol : method drawRectangle (int,java.awt.Rectangle,int,int)
    location: class java.awt.Graphics
    g.drawRectangle(rec.x, rec[i], rec[i].height, rec[i].width );
    ^
    3 errors
    Errors compiling Worm.java.
    The code follows:
    Thanks for any assistance inadvance
    WBR
    import java.awt.*;
    import java.awt.Graphics.*;
    import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.Rectangle.*;
    import java.io.*;
    import java.util.*;
    class WormFrame extends JFrame{   
        public WormFrame(){
            setTitle("CenteredFrame");
            addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e){
                    System.exit(0);
            Toolkit tk = Toolkit.getDefaultToolkit();
            Dimension d = tk.getScreenSize();
            int screenHeight = d.height;
            int screenWidth = d.width;
            setSize(screenWidth / 2, screenHeight / 2);
            setLocation(screenWidth / 4, screenHeight / 4);
    public class Worm{
        Rectangle rec[];
        private Worm(){
            Rectangle rec[] = new Rectangle [25];
            int x = 25;
            int y = 25;
            for(int i = 0; i < rec.length; i++ ){
                rec.x = x++;
    rec[i].y = y++;
    rec[i].height = 1;
    rec[i].width = 1;
    private void wormDraw( ){
    setForeground(Color.RED); // Error 1
    for(int a = 1; a < 20; a++){
    for(int i = 1; i < rec.length; i++ ){
    rec[i].x += 1;
    rec[i].y += 1;
    repaint(); // Error 2
    public void paint(Graphics g) {
    System.out.println("paint : " + new Date( ) );
    // Draw dots
    for(int i = 0; i < rec.length; i++ ){
    g.drawRectangle(rec[i].x, rec[i], rec[i].height, rec[i].width ); // Error 3
    public static void main(String[] args){
    JFrame frame = new WormFrame();
    frame.show();
    Worm w = new Worm();
    w.wormDraw();

    Hello! This works...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.*;
    public class Worm extends JFrame
         Rectangle rec[];   
         public Worm()
               setTitle("CenteredFrame");       
            addWindowListener(new WindowAdapter(){
                 public void windowClosing(WindowEvent e){               
                     System.exit(0);           
            Toolkit tk = Toolkit.getDefaultToolkit();       
            Dimension d = tk.getScreenSize();       
            int screenHeight = d.height;       
            int screenWidth = d.width;       
            setSize(screenWidth / 2, screenHeight / 2);       
            setLocation(screenWidth / 4, screenHeight / 4);  
            setVisible(true);
              rec = new Rectangle [25];       
              int x = 25;       
              int y = 25;       
              for(int i = 0; i < rec.length; i++ )
                   System.out.println("Creating rec " + i);        
                   rec[i] = new Rectangle();
                   rec.x = x++;
                   rec[i].y = y++;
                   rec[i].height = 1;
                   rec[i].width = 1;
         public void wormDraw( )
              setForeground(Color.RED);
              for(int a = 1; a < 20; a++)
                   for(int i = 1; i < rec.length; i++ )
                        System.out.println("Drawing rec " + i);
                        rec[i].x += 1;
                        rec[i].y += 1;
              System.out.println("Calling paint");
              repaint();
              validate();
              System.out.println("Done");
         public void paint(Graphics g)
              System.out.println("paint : " + new Date( ) );
              for(int i = 0; i < rec.length; i++ )
                   g.fillRect(rec[i].x, rec[i].y, rec[i].height, rec[i].width);
         public static void main(String[] args)
              new Worm().wormDraw();           
    regards,
    Liam

  • Cannot resolve symbol class graphics

    does anyone know what the error
    cannot resolve symbol class graphics means?
    with this code i can't seem to call the graphics method to draw the line....any reason why?
    import javax.swing.*;
    import java.*;
    public class LineDraw extends JFrame {
        public static void main(String[] args) {
            LineDraw ld = new LineDraw();
            ld.setSize(500,500);
            ld.setVisible(true);
            ld.enterVariables();
        public void init(){
        private int x1;
        private int x2;
        private int y1;
        private int y2;
        public void paint(Graphics g) {
            g.GetGraphics(g);
            super.paintComponent(g);
            g.drawLine(x1, y1, x2, y2);
        public void enterVariables() {
            x1 = Integer.parseInt(JOptionPane.showInputDialog("Enter x1:"));
            y1 = Integer.parseInt(JOptionPane.showInputDialog("Enter y1:"));
            x2 = Integer.parseInt(JOptionPane.showInputDialog("Enter x2:"));
            y2 = Integer.parseInt(JOptionPane.showInputDialog("Enter y2:"));
            repaint();
    }

    well the exact error message is ...by the way now that i think about it
    if the graphics method shoudl not be part of the JFrame class then what method would i use to draw 2D Graphics?
    --------------------Configuration: <Default>--------------------
    C:\Documents and Settings\c1s5\My Documents\LineDraw.java:21: cannot resolve symbol
    symbol : class Graphics
    location: class LineDraw
    public void paint(Graphics g)
    ^
    1 error
    Process completed.
    and the exact code is
    import javax.swing.*;
    import java.*;
    public class LineDraw extends JFrame {
        public static void main(String[] args) {
            LineDraw ld = new LineDraw();
            ld.setSize(1024,500);
            ld.setVisible(true);
            ld.enterVariables();
        private int x1;
        private int x2;
        private int y1;
        private int y2;
        public void paint(Graphics g)
            super.paintComponent(g);
            g.drawLine(x1, y1, x2, y2);
        public void enterVariables() {
            x1 = Integer.parseInt(JOptionPane.showInputDialog("Enter x1:"));
            y1 = Integer.parseInt(JOptionPane.showInputDialog("Enter y1:"));
            x2 = Integer.parseInt(JOptionPane.showInputDialog("Enter x2:"));
            y2 = Integer.parseInt(JOptionPane.showInputDialog("Enter y2:"));
            repaint();
    }

  • Import java.util.Formatter - cannot resolve symbol

    I use j2sdk1.4.2_04
    when I try to compile my program using Formatter, it response error "cannot resolve symbol"
    Pls help!

    Where did you get this java.util.Formatter from? If you check the official 1.4.2 API for Java, that class does not exisit! However, java.util.logging.Formatter, does exisit...
    http://java.sun.com/j2se/1.4.2/docs/api/
    If you ment: java.util.logging.Formatter have you checked the API to make sure you are using it correctly???
    HTH.

  • Sequential.java [28:1] cannot resolve symbol

    The program asks users to enter random numbers.They are stored in a vector. The numbers are then added and the results of the addition stored in an vector.ie
    sum1=item1
    sum2=item1+item2
    sum3=item1+item2+item3
    sumn=item1+item2+,,,,,+itemn
    here is the program
    import java.util.Vector;
    import java.io.*;
    public class Sequential {
    /** Creates a new instance of Sequential */
    public Sequential() {
    public static int inputInt(String str){
    BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
    System.out.println(str);
    int val;
    try{
    val = Integer.parseInt(input.readLine());
    }catch(Exception e){}
    return val;
    public static void main (String args[]){
    //initialising
    Vector myarray = new Vector();
    Vector sum = new Vector();
    int ans = 0;
    int dim;
    dim = inputInt("Enter the array dimension");
    //populate the
    for(int i=0; i < dim; i++){
    myarray.add(i,inputInt("Enter the array dimension"));
    for(int i=0; i < dim; i++ ){
    ans = Integer.parseInt(myarray.get(i)) + ans;
    sum.add(i,ans);
    for(int i=0; i < dim; i++){
    System.out.println("Item [" + i + "] is " + sum.get(i));
    it dispalys on ".add" part
    Sequential.java [28:1] cannot resolve symbol in
    myarray.add(i,inputInt("Enter the array dimension"));

    Vectors store objects, not primitives.
    Try the Integer wrapper class, e.g. myarray.add(i, new Integer(inputInt("Enter the array dimension")));
    There are some other code problems I think you'll notice, but you should be able to work those out.

  • Java Bean Error in JSP: Cannot Resolve Symbol FirstBean

    I have created a java bean with following package statement
    package mybeans;
    and my bean name is
    FirstBean
    it compile secessfully and now my directory structure is following
    WebAppRootDir \ WEB-INF \ classes \ mybeans \ FirstBean.class
    I am using Tomcat 4.1 and in JSP i am declaring the bean with following line
    <jsp:useBean id="b" class="mybeans.FirstBean" />
    and tomcat 4.1 is failed to find this bean and giving me following error
    cannot resolve symbol
    symbol  : class StudentBean 
    location: package mybeans
    mybeans.FirstBean b = null;
    all my class and directory structure is ok i am puzzle why this error is coming, plz help me quickly i need solution quickly ...

    Error is for StudentBean, not for FirstBean. So check for it.

  • Java Bean Error in JSP: Cannot Resolve Symbol Error

    I have created a java bean with following package statement
    package mybeans;
    and my bean name is
    FirstBean
    it compile secessfully and now my directory structure is following
    WebAppRootDir \ WEB-INF \ classes \ mybeans \ FirstBean.class
    I am using Tomcat 4.1 and in JSP i am declaring the bean with following line
    <jsp:useBean id="b" class="mybeans.FirstBean" />
    and tomcat 4.1 is failed to find this bean and giving me following error
    cannot resolve symbol
    symbol  : class FirstBean 
    location: package mybeans
    mybeans.FirstBean b = null;
    all my class and directory structure is ok i am puzzle why this error is coming, plz help me quickly i need solution quickly ...

    It seem to be ok... why dont your try with a newer versi�n of Tomcat?

  • Error : Cannot resolve symbol shape

    I get the following error message
    <---------------------------------------------------------------------->
    C:\RandomShapeApplet.java:87: cannot resolve symbol
    symbol : variable shape
    location: class RandomShapeApplet
              return shape;
    ^
    1 error
    Tool completed with exit code 1
    <---------------------------------------------------------------------->
    RandomShapeApplet.java
    <---------------------------------------------------------------------->
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Rectangle2D;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import java.awt.Shape;
    import java.util.Random;
    public class RandomShapeApplet extends Applet
         Random generator;
         private double width;
         private double height;
         private double x1;
         private double y1;
         private double x2;
         private double y2;
         private double xTopLeft;
         private double yTopLeft;
         private double wdth;
         private double hght;
         private final double MIN = 0;
         private int rndValue;
         public RandomShapeApplet()
              generator = new Random();
              width = getWidth();
              height = getHeight();
         public Shape randomShape()
              rndValue = generator.nextInt(3);
              x1 = generator.nextDouble() * ((width + 1) - MIN) + MIN;
              y1 = generator.nextDouble() * ((height + 1) -MIN) + MIN;
              x2 = generator.nextDouble() * ((width + 1) - MIN) + MIN;
              y2 = generator.nextDouble() * ((height + 1) -MIN) + MIN;
              if (rndValue == 0 || rndValue == 1)
                   hght = Math.abs(y2 - y1);
                   wdth = Math.abs(x2 - x1);
                   if (y2 > y1)
                        yTopLeft = y1;
                   else if (y1 >= y2)
                        yTopLeft = y2;
                   if (x2 > x1)
                        xTopLeft = x1;
                   else if (x1 >= x2)
                        xTopLeft = x2;
                   if (rndValue == 0)
                        Rectangle2D.Double shape = new Rectangle2D.Double(xTopLeft, yTopLeft, wdth, hght);
                   else if (rndValue == 1)
                        Ellipse2D.Double shape = new Ellipse2D.Double(xTopLeft, yTopLeft, wdth, hght);
              else if (rndValue == 2)
                   Line2D.Double shape = new Line2D.Double(x1, y1, x2, y2);
              return shape;
         public void paint(Graphics g)
              Graphics2D g2 = (Graphics2D)g;
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());
              g2.draw(randomShape());

    The problem is in this part of your code...
    if (rndValue == 0)
       Rectangle2D.Double shape = new Rectangle2D.Double(xTopLeft, yTopLeft, wdth, hght);
    else if (rndValue == 1)
       Ellipse2D.Double shape = new Ellipse2D.Double(xTopLeft, yTopLeft, wdth, hght);
    else if (rndValue == 2)
       Line2D.Double shape = new Line2D.Double(x1, y1, x2, y2);
    return shape;In the code, the variable shape is always defined within {} which means the scope of the variable is only between the {}. So you can not return shape because you have not defined a variable named shape outside of the if statements. I think it will work to use
    Shape shape=null;
    if (rndValue == 0)
       shape = (Shape) new Rectangle2D.Double(xTopLeft, yTopLeft, wdth, hght);
    }And make similar changes to the rest of the code. I am assuming the rest of the objects also implement the Shape interface.

  • Cannot resolve symbol--Shape

    I am having a problem with the following code in InheritanceDemo.java.
    public void paint(Graphics g)
    numShapes = shapeList.size();
    for (int i = 0;i < numShapes; i++)
    Shape s = (Shape)shapeList.get(i);
    s.draw(g);
    It is giving me errors on s.draw(g). It's pointing to the period after the s and says "cannot resolve symbol", Class Shape.
    My Shape.java looks like the following:
    import java.awt.*;
    abstract class Shape {
    abstract void paint(Graphics g);
    Can anyone tell me what I've done incorrectly?

    Okay, I think I understand. You're importing java.awt.*, so when you say Shape it thinks you mean java.awt.Shape.
    (Solution 1) Change the classname Shape to one which doesn't already exist in the Java class library.
    (Solution 2) Only import the classes you need, not *.
    (Solution 3) Add an explicit "import Shape;" below the rest of the import statements to override

  • Cannot resolve symbol: method getCodeBase ()

    I`m creating a dice game that makes a sound when player wins or looses. Instaed I`m getting the following error message: Cannot resolve symbol: method getCodeBase (). I think this depends on the fact that I have a separate applet launcher but cannot figure out how to solve this, please help!!
    This is the applet launcher
    import javax.swing.*;
    import java.awt.*;
    // [MC] Public class DiceApplet
    public class DiceApplet extends JApplet
         // [MC] Constructor.
         public DiceApplet()
              // [MC] Sets the contentPane property. This method is called by the constructor.
              this.setContentPane(new DicePanel());
    This is the die class
    import java.awt.*;
    import javax.swing.*;
    // [MC] Public class Die
    public class Die extends JPanel
        // ======================================================================
        // [MC] Instance variable.
        private int myFaceValue;     // [MC] Value that shows on face of die.
        // [MC] End instance variable.
        // ======================================================================
        // [MC] Constructor.
        // [MC] Initialises die to blue background and initial roll.
        public Die()
              // [MC] Sets the background colour of the die to blue.
              setBackground(Color.blue);
              // [MC] Sets the foreground colour of the die to gray.
              setForeground(Color.gray);
              // [MC] Sets the border colour of the die to white.
              setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.white));
              // [MC] Sets to random initial value.
              roll();
         }     // [MC] End constructor.
        // ======================================================================
        // [MC] Method roll.
        // [MC] Produces random roll in the range of 1 to 6.
        public int roll()
            int val = (int)(6*Math.random() + 1);   // [MC] Range from 1 to 6.
            setValue(val);
            return val;     // [MC] Returns a value from 1 to 6.
        }     // [MC] End method roll.
        // [MC] Method setValue
        // [MC] Sets the value of the die. Causes repaint.
        public void setValue(int dots)
            myFaceValue = dots;
            repaint();    // [MC] Value has changed, must repaint.
        } // [MC] End method setValue.
        // ======================================================================
        // [MC] Method getValue.
        // [MC] Returns result of last roll.
        public int getValue()
            return myFaceValue;
        } // [MC] End method getValue.
        // ======================================================================
        // [MC] Method paintComponent.
        // [MC] Draws dots of die face.
        public void paintComponent(Graphics g)
              // [MC] Call superclass's paint method.
            super.paintComponent(g);
              // [MC] Sets panel width.
            int w = getWidth();
            // [MC] Sets panel height.
            int h = getHeight();
              // [MC] Draws border.
            g.drawRect(0, 0, w-1, h-1);
            // Switch
            switch (myFaceValue)
                case 1: drawDot(g, w/2, h/2);
                        break;
                case 3: drawDot(g, w/2, h/2);
                case 2: drawDot(g, w/4, h/4);
                        drawDot(g, 3*w/4, 3*h/4);
                        break;
                case 5: drawDot(g, w/2, h/2);
                case 4: drawDot(g, w/4, h/4);
                        drawDot(g, 3*w/4, 3*h/4);
                        drawDot(g, 3*w/4, h/4);
                        drawDot(g, w/4, 3*h/4);
                        break;
                case 6: drawDot(g, w/4, h/4);
                        drawDot(g, 3*w/4, 3*h/4);
                        drawDot(g, 3*w/4, h/4);
                        drawDot(g, w/4, 3*h/4);
                        drawDot(g, w/4, h/2);
                        drawDot(g, 3*w/4, h/2);
                        break;
            } // [MC] End switch.
        }     // [MC] End method paintComponent.
        // [MC] Method drawDot.
        /** Utility method used by paintComponent(). */
        private void drawDot(Graphics g, int x, int y)
            // [MC] Gets panel width.
              int w = getWidth();
              // [MC] Gets panel height.
              int h = getHeight();
              // [MC] Local variable.
            int d;
            // [MC] Sets diameter of dot proportional to panel size.
            d = (w + h)/10;
              // [MC] Sets colour for dot to white.
              Color myDotColor = new Color(255, 255, 255);
              g.setColor(myDotColor);
             // [MC] Draws dot.
             g.fillOval(x-d/2, y-d/2, d, d);
        } // [MC] End method drawDot.
    This is the class giving the error message
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.applet.AudioClip;
    import java.applet.Applet;
    import java.net.*;
    // [MC] Public class DicePanel
    public class DicePanel extends JPanel
        // ======================================================================
        // [MC] Instance variables.
        // [MC] Creates new instances of the component for the die.
        private Die myLeftDie;     // [MC] Component for left die.
        private Die myRightDie;     // [MC] Component for right die.
         // [MC] Creates the button (rollButton) to roll the dice.
         private     JButton rollButton = new JButton("Roll Dice");
         // [MC] Creates the text fields. Creates new instance of JTextField.
         // [MC] Creates the text field (rollNumberTextField) to display number of rolls.
         private JTextField rollNumberTextField = new JTextField(20);
         // [MC] Creates the text field (rollResultTextField) to display result of roll.
         private JTextField rollResultTextField = new JTextField(20);
         // [MC] Creates the text field (rollPointsTextField) to display the player`s points.
         private JTextField rollPointsTextField = new JTextField(20);
         // [MC] Creates the text field (gameFinalResultTextField) to display the final game result.
         private JTextField gameFinalResultTextField = new JTextField(20);
        // [MC] Initialises instance variables declared in the inner listeners.
        private int result = 0, resultLeft = 0, resultRight = 0;
         private int rolls = 0;
         private int finalResult = 0;
         private int points = 0;
         private boolean first = true;
         private AudioClip winClip = null;
         private AudioClip looseClip = null;
        // ======================================================================
        // [MC] Constructor. Creates border layout panel.
        DicePanel()
            // [MC] Creates the dice
            myLeftDie  = new Die();
            myRightDie = new Die();
        // ======================================================================
              // [MC] Creates the buttons.
              // [MC] Creates the button (newGameButton) to start new game.
            JButton newGameButton = new JButton("New Game");
              // *[MC] Creates the button (rollButton) to roll the dice.
            // *JButton rollButton = new JButton("Roll Dice");
            // [MC] Sets the font of the buttons.
            // [MC[ Sets the font of the button newGameButton.
            newGameButton.setFont(new Font("Batang", Font.BOLD, 20));
            // [MC[ Sets the font of the button rollButton.
            rollButton.setFont(new Font("Batang", Font.BOLD, 20));
                // [MC] Sets the button border format.
              // [MC] Sets the button with compound borders.
            Border compound;
              // [MC] Border format local variables.
            Border blackline, raisedetched, loweredetched, raisedbevel, loweredbevel, empty;
              // [MC] Initialises border formats.
              //blackline = BorderFactory.createLineBorder(Color.gray);
              raisedetched = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
              loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
              raisedbevel = BorderFactory.createRaisedBevelBorder();
              //loweredbevel = BorderFactory.createLoweredBevelBorder();
              // [MC] Sets compound border format.
            compound = BorderFactory.createCompoundBorder(raisedetched, raisedbevel);
            // [MC] Sets the button (newGameButton) with compound border format.
            newGameButton.setBorder(compound);
            // [MC] Sets the button (rollButton) with compound border format.
              rollButton.setBorder(compound);
            // [MC] Adds listener.
            // [MC] Adds listener to rollButton.
            rollButton.addActionListener(new RollListener());
            // [MC] Adds listener to newGameButton.
            newGameButton.addActionListener(new NewGameListener());
        // ======================================================================
              // [MC] Creates the labels. Creates new instance of JLabel.
              // [MC] Creates the label (rollNumberLabel) for the number of rolls.
              JLabel rollNumberLabel = new JLabel("Roll Number");
              // [MC] Creates the label (rollResultLabel) for the result of roll.
              JLabel rollResultLabel = new JLabel("Roll Result");
              // [MC] Creates the label (rollPointsLabel) for the player`s points.
              JLabel rollPointsLabel = new JLabel("Player Points");
              // [MC] Creates the label (gameFinalResult) for the final game result.
              JLabel gameFinalResultLabel = new JLabel("Final Result");
              // [MC] Sets the label font.
              rollNumberLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
              rollResultLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
              rollPointsLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
              gameFinalResultLabel.setFont(new Font("Sansserif", Font.PLAIN, 10));
              // [MC] Sets the label title alignment.
              rollNumberLabel.setHorizontalAlignment(JLabel.CENTER);
              rollResultLabel.setHorizontalAlignment(JLabel.CENTER);
              rollPointsLabel.setHorizontalAlignment(JLabel.CENTER);
              gameFinalResultLabel.setHorizontalAlignment(JLabel.CENTER);
              // [MC] Sets the label border format.
              //rollNumberLabel.setBorder(loweredetched);
              //rollResultLabel.setBorder(loweredetched);
              //rollPointsLabel.setBorder(loweredetched);
              //gameFinalResultLabel.setBorder(loweredetched);
        // ======================================================================
              // [MC] Sets the text field font.
              rollNumberTextField.setFont(new Font("Sansserif", Font.PLAIN, 16));
              rollResultTextField.setFont(new Font("Sansserif", Font.PLAIN, 16));
              rollPointsTextField.setFont(new Font("Sansserif", Font.PLAIN, 16));
              gameFinalResultTextField.setFont(new Font("Sansserif", Font.BOLD, 16));
              // [MC] Sets the text field text alignment.
              rollNumberTextField.setHorizontalAlignment(JTextField.CENTER);
              rollResultTextField.setHorizontalAlignment(JTextField.CENTER);
              rollPointsTextField.setHorizontalAlignment(JTextField.CENTER);
              gameFinalResultTextField.setHorizontalAlignment(JTextField.CENTER);
              // [MC] Sets the text field text colour.
              gameFinalResultTextField.setForeground(Color.blue);
              // [MC] Sets the text field to not editable.
              rollNumberTextField.setEditable(false);
              rollResultTextField.setEditable(false);
              rollPointsTextField.setEditable(false);
              gameFinalResultTextField.setEditable(false);
        // ======================================================================
              // [MC] Gets sounds.
              winClip =  getAudioClip(getCodeBase(), "bunny1.au");
              looseClip =  getAudioClip(getCodeBase(), "bunny1.au");
        // ======================================================================
              // [MC] Sets the layout manager (GridBagLayout) for this container.
              this.setLayout(new GridBagLayout());
              // [MC] Creates new instance of GridBagConstraints.
              GridBagConstraints c = new GridBagConstraints();
              // [MC] Makes the component fill its display area entirely.
              c.fill = GridBagConstraints.BOTH;
              // [MC] Layouts components.
              // [MC] Adds the component newGameButton to this container.
              c.gridx = 0;     // [MC] Makes this component the leftmost column (column 1).
              c.gridy = 0;     // [MC] Makes this component the uppermost row (row 1).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 2;     // [MC] Specifies the number of columns the component uses (2 columns).
              this.add(newGameButton, c);     // [MC] Adds the button newGameButton.
              // [MC] Adds the component rollButton to this container.
              c.gridx = 2;     // [MC] Makes this component the third column from left (column 3).
              c.gridy = 0;     // [MC] Make this component the uppermost row (row 1).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 rows).
              c.gridwidth = 2;     // [MC] Specifies the number of columns the component uses (2 columns).
              this.add(rollButton, c);     // [MC] Adds the button rollButton.
              // [MC] Adds the component rollNumberLabel to this container.
              c.gridx = 0;     // [MC] Makes this component the leftmost column (column 1).
              c.gridy = 3;     // [MC] Makes this component the third row from top (row 3).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              c.weightx = 0.1;     // [MC] Requests any extra vertical (column) space.
              this.add(rollNumberLabel, c);     // [MC] Adds the label rollNumberLabel.
              // [MC] Adds the component rollResultLabel to this container.
              c.gridx = 1;     // [MC] Makes this component the second column from left (column 2).
              c.gridy = 3;     // [MC] Makes this component the third row from top (row 3).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              this.add(rollResultLabel, c);     // [MC] Adds the label rollResultLabel.
              // [MC] Adds the component rollPointsLabel to this container.
              c.gridx = 2;     // [MC] Makes this component the third column from left (column 3).
              c.gridy = 3;     // [MC] Makes this component the third row from top (row 3).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              this.add(rollPointsLabel, c);     // [MC] Adds the label rollPointsLabel.
              // [MC] Adds the component gameFinalResultLabel to this container.
              c.gridx = 3;     // [MC] Makes this component the fourth column from left (column 4).
              c.gridy = 3;     // [MC] Makes this component the third row from top (row 3).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              this.add(gameFinalResultLabel, c);     // [MC] Adds the label gameFinalResultLabel.
              // [MC] Adds the component rollNumberTextField to this container.
              c.gridx = 0;     // [MC] Makes this component the leftmost column (column 1).
              c.gridy = 4;     // [MC] Makes this component the fourth row from top (row 4).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              c.weightx = 0.1;     // [MC] Requests any extra vertical (column) space.
              this.add(rollNumberTextField, c);     // [MC] Adds the text field rollNumberTextField.
              // [MC] Adds the component rollResultTextField to this container.
              c.gridx = 1;     // [MC] Makes this component the second column from left (column 2).
              c.gridy = 4;     // [MC] Makes this component the fourth row from top (row 4).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              this.add(rollResultTextField, c);     // [MC] Adds the text field rollResultTextField.
              // [MC] Adds the component rollPointsTextField to this container.
              c.gridx = 2;     // [MC] Makes this component the third column from left (column 3).
              c.gridy = 4;     // [MC] Makes this component the fourth row from top (row 4).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              this.add(rollPointsTextField, c);     // [MC] Adds the text field rollPointsTextField.
              // [MC] Adds the component gameFinalResultTextField to this container.
              c.gridx = 3;     // [MC] Makes this component the fourth column from left (column 4).
              c.gridy = 4;     // [MC] Makes this component the fourth row from top (row 4).
              c.gridheight = 1;     // [MC] Specifies the number of rows the component uses (1 row).
              c.gridwidth = 1;     // [MC] Specifies the number of columns the component uses (1 column).
              this.add(gameFinalResultTextField, c);     // [MC] Adds the text field gameFinalResultTextField.
              // [MC] Adds the component myLeftDie to this container.
              c.gridx = 0;     // [MC] Makes this component the leftmost column (column 1).
              c.gridy = 1;     // [MC] Makes this component the second row from top (row 2).
              c.gridheight = 2;     // [MC] Specifies the number of rows the component uses (2 rows).
              c.gridwidth = 2;     // [MC] Specifies the number of columns the component uses (2 columns).
              c.weightx = 1.0;     // [MC] Requests any extra vertical (column) space.
              c.weighty = 1.0;     // [MC] Requests any extra horizontal (row) space.
              this.add(myLeftDie, c);     // [MC] Adds the component myLeftDie.
              // [MC] Adds the component myRightDie to this container.
              c.gridx = 2;     // [MC] Makes this component the third column from left (column 3).
              c.gridy = 1;     // [MC] Makes this component the second row from top (row 2).
              c.gridheight = 2;     // [MC] Specifies the number of rows the component uses (2 rows).
              c.gridwidth = 2;     // [MC] Specifies the number of columns the component uses (2 column).
              c.weightx = 1.0;     // [MC] Requests any extra column (vertical) space.
              c.weighty = 1.0;     // [MC] Requests any extra horizontal (row) space.
              this.add(myRightDie, c);     // [MC] Adds the component myRightDie.
        }     // [MC] end constructor
        // ======================================================================
        // [MC] Private class RollListener
        // [MC] Inner listener class for rollButton.
        private class RollListener implements ActionListener
            public void actionPerformed(ActionEvent e)
                // [MC] Rolls the dice.
                myLeftDie.roll();     // [MC] Rolls left die.
                myRightDie.roll();     // [MC] Rolls right die.
                   finalResult = 0; // [MC] If result = 0 then game is not over.
                   rolls++;     // [MC] Increments the number of rolls.
                  // [MC] Displays the roll number.
                    rollNumberTextField.setText(" " + rolls + " ");
                   // [MC] Returns the result (number of dots) of last roll.
                   resultLeft = myLeftDie.getValue();     // [MC] Returns the result of the left die.
                   resultRight = myRightDie.getValue();     // [MC] Returns the result of the right die.
                   result = resultLeft + resultRight;     // [MC] Returns the total result of dice.
                   // [MC] Displays the result of last roll.
                   rollResultTextField.setText(" " + result + " ");
                   // [MC] Sets the rules for the game.
                   // [MC] Sets the rules for the first roll of dice.
                   if (first)
                       // [MC] If the result is 2, 3 or 12 on the first throw, the player loses.
                       if (result == 2 || result == 3 || result == 12)
                             finalResult = 2; // [MC] If result = 2 then the player loses and the game is over.
                             gameFinalResultTextField.setText("LOOSE");
                             Toolkit.getDefaultToolkit().beep();
                           rollButton.setEnabled(false);     // [MC] Disable rollButton.
                             first = true; // [MC] Game over after first roll.
                       // [MC] If the result is 7 or 11 on the first throw, the player wins.
                        else if (result == 7 || result == 11)
                             finalResult = 1; // [MC] If result = 1 then the player wins and the game is over.
                             gameFinalResultTextField.setText("WIN");
                             //Toolkit.getDefaultToolkit().beep();
                           rollButton.setEnabled(false);     // [MC] Disable rollButton.
                             first = true;     // [MC] Game over after first roll.
                        // [MC] If the player didn`t win or lose then the results 4, 5, 6, 8, 9 or 10 become the player`s point.
                        else if (result == 4 || result == 5 || result == 6 || result == 8 || result == 9 || result == 10);
                             // [MC] Returns the player`s points.
                             points = result;     // [MC] Returns the player`s points.
                             // [MC] Displays the player`s points.
                             rollPointsTextField.setText(" " + points + " ");
                             first = false;     // [MC] Game is not over after first roll.
                   // [MC] Sets the rules for the next rolls (from second roll onwards) of the dice.
                   // [MC] If the result is 7, then the player loses.
                   else if (result == 7)
                        finalResult = 2;     // [MC] If result = 2 then the player loses and the game is over.
                        gameFinalResultTextField.setText("LOOSE");
                        Toolkit.getDefaultToolkit().beep();
                      rollButton.setEnabled(false);     // [MC] Disable rollButton.
                   // [MC] If the result is equal to the player`s point, then the player wins.
                   else if (result == points)
                        finalResult = 1;     // [MC] If result = 1 then the player wins and the game is over.
                        gameFinalResultTextField.setText("WIN");
                        winClip.play();
                        //Toolkit.getDefaultToolkit().beep();
                      rollButton.setEnabled(false);     // [MC] Disable rollButton.
              }     // [MC] End public void actionPerformed(ActionEvent e).
         }     // [MC] End private class RollListener.
        // ======================================================================
        // [MC] Private class NewGameListener
        // [MC] Inner listener class for newGameButton.
        private class NewGameListener implements ActionListener
              public void actionPerformed(ActionEvent e)
                   // [MC] Initialises instance variables.
                   first = true;     // [MC] Initialise dice roll to first roll.
                   rolls = 0;     // [MC] Initialises number of rolls to 0.
                   // [MC] Initialises text fields.
                   rollResultTextField.setText("");
                   rollNumberTextField.setText("");
                   rollPointsTextField.setText("");
                   gameFinalResultTextField.setText("");
                   rollButton.setEnabled(true);     // [MC] Enable rollButton.
            } // [MC] End public void actionPerformed(ActionEvent e).
         }// [MC] End private class NewGameListener implements ActionListener.
    } // [MC] End public class DicePanel extends JPanel.

    make a backup copy before these changes
    it now compiles, but I haven't run/tested it
    changed constructor to init(), extending Applet, not JApplet
    // [MC] Public class DiceApplet
    public class DiceApplet extends Applet
      // [MC] Constructor.
      public void init()
        // [MC] Sets the contentPane property. This method is called by the constructor.
        add(new DicePanel());
    }then the 'error lines' become
        winClip =  ((Applet)getParent()).getAudioClip(((Applet)getParent()).getCodeBase(), "bunny1.au");
        looseClip =  ((Applet)getParent()).getAudioClip(((Applet)getParent()).getCodeBase(), "bunny1.au");there might be additional problems when you run/test it, but this might get you started

  • Problem using PixelGrabber ( cannot resolve symbol ) - newbie

    Hi All,
    I have a problem with my short program because the compiler write this (jdk1.4) :
    img.java:17: cannot resolve symbol
    symbol : constructor PixelGrabber (java.awt.Image,int,int,int,int,int[],int)
    location: class java.awt.image.PixelGrabber
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this
    ),image.getHeight(this),pixels,0);
    ^
    1 error
    ... And I wrote that in my code :
    ( all is OK, the bug is only when I uncomment the line where the PixelGrabber object
    is needed in my program ).
    Thanks if you have any idea of solution to solve this problem or a doc,
    ( I don't find the answer to my problem in http://java.sun.com/j2se/1.4/docs/api/java/awt/image/PixelGrabber.html ),
    import java.awt.*;
    import java.awt.image.*;
    import java.applet.*;
    import java.awt.image.PixelGrabber;
    public class img extends Applet {
    Image image;
    int pixels[];
    public void init() {
    image = getImage(getDocumentBase(), "rouge.jpg");
    pixels = new int[image.getWidth(this) * image.getHeight(this)];
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
         pg.grabPixels();
    public void paint(Graphics g) {
              String s = Integer.toString(pixels[5], 16);
              g.drawString(s, 50, 50);

    Hi,
    PixelGrabber needs one more parameter scansize (width).
    change this line;
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
    to:
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0, image.getWidth(this)
    );

  • "cannot resolve symbol" error when using super.paintComponent

    I am trying to override the paintComponent method in a class extending a JFrame, but when I call super.paintComponent(g) from inside the overridden method I get the error
    QubicGUI.java:63: cannot resolve symbol
    symbol : method paintComponent (java.awt.Graphics)
    location: class javax.swing.JFrame
    super.paintComponent(g);
    ^
    1 error
    I can't see where I am deviating from examples I know work. It is a very small program, so I have included it here:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import java.net.URL;
    class QubicGUI extends JFrame
         private int width;
         private int height;
         private Image background;
         public int getWidth()
         {     return width;     }
         public int getHeight()
         {     return height;     }
         public boolean isOpaque()
    return true;
         public QubicGUI()
              super("Qubic"); //set title
              // The following gets the default screen device for the purpose of finding the
              // current settings of height and width of the screen
         GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
              GraphicsDevice device = environment.getDefaultScreenDevice();
              DisplayMode display = device.getDisplayMode();
              width = display.getWidth();
              height = display.getHeight();
              // Here we set the window to cover the entire screen with a black background, and
              // remove the decorations. (This includes the title bar and close, minimize and
              // maximize buttons and the border)
              setUndecorated(false);
              setVisible(true);
              setSize(width,height);
              setResizable(false);
              setBackground(Color.black);
              // Initializes the background Image
              Image background = Toolkit.getDefaultToolkit().getImage("background.gif");
              // This is included for debugging with a decorated window.
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } // end constructor
              public void paintComponent(Graphics g)
                   super.paintComponent(g);     
              } // end paintComponenet
    } // end QubicGUI

    Two things I want to know:
    1. I was trying to access a variable as JLabel
    myLabel; defined in the constructor of a class from
    the constructor of another class. I got this error
    message - "Cannot access non-static variable from a
    static context". Why(When both are non-static am I
    getting the message as static context)?Post some code. It's hard to pinpoint a syntax error like that without seeing the code.
    Also, there may be cleaner ways of doing what you want without having classes sharing labels.
    2. I am using a map to set the attributes of a font.
    One of the key-value pair of the map is
    TextAttributesHashMap.put(TextAttribute.FOREGROUND,Colo
    .BLUE);
    But when I using the statement g.drawString("First
    line of the address", 40, 200); the text being
    displayed is in black and not blue. Why?You need to use the drawString that takes an AttributedCharacterIterator:
    import java.awt.*;
    import java.awt.font.*;
    import java.text.*;
    import javax.swing.*;
    public class Example  extends JPanel {
        public static void main(String[] args)  {
            JFrame f = new JFrame("Example");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container cp = f.getContentPane();
            cp.add(new Example());
            f.setSize(400,300);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            String text = "Every good boy does fine always";
            AttributedString as = new AttributedString(text);
            as.addAttribute(TextAttribute.FAMILY, "Lucida Bright");
            as.addAttribute(TextAttribute.SIZE, new Float(16));
            as.addAttribute(TextAttribute.FOREGROUND, Color.BLUE, 0, 5);
            as.addAttribute(TextAttribute.FOREGROUND, Color.GREEN, 6, 10);
            as.addAttribute(TextAttribute.FOREGROUND, Color.RED, 11, 14);
            as.addAttribute(TextAttribute.FOREGROUND, Color.YELLOW, 15, 19);
            as.addAttribute(TextAttribute.FOREGROUND, Color.MAGENTA, 20, 24);
            as.addAttribute(TextAttribute.FOREGROUND, Color.CYAN, 25, 31);
            g.drawString(as.getIterator(), 10, 20);

  • "cannot resolve symbol" in a Timer !!!Please Help!!!

    I am doing a program for a class which involves timers. I am using JCreator and when i try to construct a new timer, the compiler points to the "new" in the line:
    Timer T1=new Timer(interval, ActionListener);
    ^
    This is what it looks like and the error reads: cannot resolve symbol; constructor Timer.
    please tell me if yiou have any information or suggestions as to how this error might be remedied.

    Sure, here it is:
    import java.awt.event.*;
    import javax.swing.Timer;
    import javax.swing.JOptionPane;
    import java.util.*;
    interface ActionListener
         void actionPerformed(ActionEvent event);     
    class Ploid
         public static void main(String[] args)
              class Car implements ActionListener
                   int mpg=30;
                   int mph=35;
                   int gtank=20;
                   int interval;
                   int changer;
                   int totalmiles;
                   Car(int x)
                        interval=x;
                   public void actionPerformed(ActionEvent event)
                        for(int c=0;c<(interval/1000);c++)
                             totalmiles=totalmiles+mph;
                        int hyt=mpg*gtank;
                        if(totalmiles>hyt)
                             int y=totalmiles-hyt;
                             totalmiles=totalmiles-y;
                             System.out.println(totalmiles);
                        else
                             System.out.println(totalmiles);
    class SUV implements ActionListener
         int mpg=15;
         int mph=55;
         int gtank=30;
         int interval;
         int changer;
         int totalmiles;
         SUV(int x)
              interval=x;
              public void actionPerformed(ActionEvent event)
                   for(int c=0;c<(interval/1000);c++)
                        totalmiles=totalmiles+mph;
                   int hyt=mpg*gtank;
                   if(totalmiles>hyt)
                        int y=totalmiles-hyt;
                        totalmiles=totalmiles-y;
                        System.out.println(totalmiles);
                   else
                        System.out.println(totalmiles);
    class Semi implements ActionListener
         int mpg=60;
         int mph=80;
         int gtank=50;
         int interval;
         int changer;
         int totalmiles;
         Semi(int x)
              interval=x;
         public void actionPerformed(ActionEvent event)
              for(int c=0;c<(interval/1000);c++)
                   totalmiles=totalmiles+mph;
              int hyt=mpg*gtank;
              if(totalmiles>hyt)
                   int y=totalmiles-hyt;
                   totalmiles=totalmiles-y;
                   System.out.println(totalmiles);
              else
                   System.out.println(totalmiles);
              String flag="y";
              String trav=JOptionPane.showInputDialog("How long do you want to drive?(1000=1 hour)");
              int t1=Integer.parseInt(trav);
              Car listen=new Car(t1);
              SUV listener2=new SUV(t1);
              Semi listener3=new Semi(t1);
              final int t2=t1/1000;
              final int t3=t1/t2;
              ActionListener listener=null;
              Timer T1=new Timer(t3, listener);
              Timer T2=new Timer(t3, listener);
              Timer T3=new Timer(t3, listener);
              while(flag.equals("y"))
                   T1.start();
                   T2.start();
                   T3.start();
                   String g=JOptionPane.showInputDialog("Do you want to drive again?");
                   if((g.equals("y"))||(g.equals("Y")))
                        System.out.println("Let's Drive!");
                   else
                        flag=g;
                   System.exit(0);
    }Here is the errors:
    [errors]
    A:\Ploid2.java:116: cannot resolve symbol
    symbol : constructor Timer (int,ActionListener)
    location: class javax.swing.Timer
              Timer T1=new Timer(t3, listener);
    ^
    A:\Ploid2.java:117: cannot resolve symbol
    symbol : constructor Timer (int,ActionListener)
    location: class javax.swing.Timer
              Timer T2=new Timer(t3, listener);
    ^
    A:\Ploid2.java:118: cannot resolve symbol
    symbol : constructor Timer (int,ActionListener)
    location: class javax.swing.Timer
              Timer T3=new Timer(t3, listener);
    ^
    3 errors
    Process completed.
    [errors]
    ****There is the source code and the errors the compiler returns. That should be more help.****

  • Class error - cannot resolve symbol "MyDocumentListener"

    Hello,
    this is a groaner I'm sure, but I don't see the problem.
    Newbie-itis probably ...
    I'm not concerned with what the class does, but it would be nice for the silly thing to compile!
    What the heck am I missing for "MyDocumentListener" ?
    C:\divelog>javac -classpath C:\ CenterPanel.java
    CenterPanel.java:53: cannot resolve symbol
    symbol : class MyDocumentListener
    location: class divelog.CenterPanel
    MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
    ^
    CenterPanel.java:53: cannot resolve symbol
    symbol : class MyDocumentListener
    location: class divelog.CenterPanel
    MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
    ^
    2 errors
    package divelog;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.lang.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.text.*;
    public class CenterPanel extends JPanel implements ActionListener
    { // Opens class
    static private final String newline = "\n";
    private JTextArea comments;
    private JScrollPane scrollpane;
    private JButton saveButton, openButton;
    private JLabel whiteshark;
    private Box box;
    private BufferedReader br ;
    private String str;
    private JTextArea instruct;
    private File defaultDirectory = new File("C://divelog");
    private File fileDirectory = null;
    private File currentFile= null;
    public CenterPanel()
    { // open constructor CenterPanel
    setBackground(Color.white);
    comments = new JTextArea("Enter comments, such as " +
    "location, water conditions, sea life you observed," +
    " and problems you may have encountered.", 15, 10);
    comments.setLineWrap(true);
    comments.setWrapStyleWord(true);
    comments.setEditable(true);
    comments.setFont(new Font("Times-Roman", Font.PLAIN, 14));
    // add a document listener for changes to the text,
    // query before opening a new file to decide if we need to save changes.
    MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
    comments.getDocument().addDocumentListener(myDocumentListener); // create the reference for the class
    // ------ Document listener class -----------
    class MyDocumentListener implements DocumentListener {
    public void insertUpdate(DocumentEvent e) {
    Calculate(e);
    public void removeUpdate(DocumentEvent e) {
    Calculate(e);
    public void changedUpdate(DocumentEvent e) {
    private void Calculate(DocumentEvent e) {
    // do something here
    scrollpane = new JScrollPane(comments);
    scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    saveButton = new JButton("Save Comments", new ImageIcon("images/Save16.gif"));
    saveButton.addActionListener( this );
    saveButton.setToolTipText("Click this button to save the current file.");
    openButton = new JButton("Open File...", new ImageIcon("images/Open16.gif"));
    openButton.addActionListener( this );
    openButton.setToolTipText("Click this button to open a file.");
    whiteshark = new JLabel("", new ImageIcon("images/gwhite.gif"), JLabel.CENTER);
    Box boxH;
    boxH = Box.createHorizontalBox();
    boxH.add(openButton);
    boxH.add(Box.createHorizontalStrut(15));
    boxH.add(saveButton);
    box = Box.createVerticalBox();
    box.add(scrollpane);
    box.add(Box.createVerticalStrut(10));
    box.add(boxH);
    box.add(Box.createVerticalStrut(15));
    box.add(whiteshark);
    add(box);
    } // closes constructor CenterPanel
    public void actionPerformed( ActionEvent evt )
    { // open method actionPerformed
    JFileChooser jfc = new JFileChooser();
    // these do not work !!
    // -- set the file types to view --
    // ExtensionFileFilter filter = new ExtensionFileFilter();
    // FileFilter filter = new FileFilter();
    //filter.addExtension("java");
    //filter.addExtension("txt");
    //filter.setDescription("Text & Java Files");
    //jfc.setFileFilter(filter);
         //Add a custom file filter and disable the default "Accept All" file filter.
    jfc.addChoosableFileFilter(new JTFilter());
    jfc.setAcceptAllFileFilterUsed(false);
    // -- open the default directory --
    // public void setCurrentDirectory(File dir)
    // jfc.setCurrentDirectory(new File("C://divelog"));
    jfc.setCurrentDirectory(defaultDirectory);
    jfc.setSize(400, 300);
    jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    Container parent = saveButton.getParent();
    //========================= Test Button Actions ================================
    //========================= Open Button ================================
    if (evt.getSource() == openButton)
    int choice = jfc.showOpenDialog(CenterPanel.this);
    File file = jfc.getSelectedFile();
    /* a: */
    if (file != null && choice == JFileChooser.APPROVE_OPTION)
    String filename = jfc.getSelectedFile().getAbsolutePath();
    // -- compare the currentFile to the file chosen, alert of loosing any changes to currentFile --
    // If (currentFile != filename)
    // -- get the current directory name -------
    // public File getCurrentDirectory( );
    File f=new File(System.getProperty("user.dir"));
    fileDirectory = jfc.getCurrentDirectory();
    // -- remember the last directory used --
    if (defaultDirectory != fileDirectory)
    {defaultDirectory = fileDirectory;}
    try
    { //opens try         
    comments.getLineCount( );
    // -- clear the old data before importing the new file --
    comments.selectAll();
    comments.replaceSelection("");
    // -- get the new data ---
    br = new BufferedReader (new FileReader(file));
    while ((str = br.readLine()) != null)
    {//opens while
    comments.append(str);
    } //closes while
    } // close try
    catch (IOException ioe)
    { // open catch
    comments.append(newline +"Open command not successful:" + ioe + newline);
    } // close catch
    // ---- display the values of the directory variables -----------------------
    comments.append(
    newline + "The f directory variable contains: " + f +
    newline + "The fileDirectory variable contains: " + fileDirectory +
    newline + "The defaultDirectory variable contains: " + defaultDirectory );
    else
    comments.append("Open command cancelled by user." + newline);
    } //close if statement /* a: */
    //========================= Save Button ================================
    } else if (evt.getSource() == saveButton)
    int choice = jfc.showSaveDialog(CenterPanel.this);
    if (choice == JFileChooser.APPROVE_OPTION)
    File fileName = jfc.getSelectedFile();
    // -- get the current directory name -------
    // public File getCurrentDirectory( );
    File f=new File(System.getProperty("user.dir"));
    fileDirectory = jfc.getCurrentDirectory();
    // -- remember the last directory used --
    if (defaultDirectory != fileDirectory)
    {defaultDirectory = fileDirectory;}
    //check for existing files. Warn users & ask if they want to overwrite
    for(int i = 0; i < fileName.length(); i ++) {
    File tmp = null;
    tmp = (fileName);
    if (tmp.exists()) // display pop-up alert
    //public static int showConfirmDialog( Component parentComponent,
    // Object message,
    // String title,
    // int optionType,
    // int messageType,
    // Icon icon);
    int confirm = JOptionPane.showConfirmDialog(null,
    fileName + " already exists on " + fileDirectory
    + "\n \nContinue?", // msg
    "Warning! Overwrite File!", // title
    JOptionPane.OK_CANCEL_OPTION, // buttons displayed
                        // JOptionPane.ERROR_MESSAGE
                        // JOptionPane.INFORMATION_MESSAGE
                        // JOptionPane.PLAIN_MESSAGE
                        // JOptionPane.QUESTION_MESSAGE
    JOptionPane.WARNING_MESSAGE,
    null);
    if (confirm != JOptionPane.YES_OPTION)
    { //user cancels the file overwrite.
    try {
    jfc.cancelSelection();
    break;
    catch(Exception e) {}
    // ----- Save the file if everything is OK ----------------------------
    try
    { // opens try
    BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
    bw.write(comments.getText());
    bw.flush();
    bw.close();
    comments.append( newline + newline + "Saving: " + fileName.getName() + "." + newline);
    break;
    } // closes try
    catch (IOException ioe)
    { // open catch
    comments.append(newline +"Save command unsuccessful:" + ioe + newline);
    } // close catch
    } // if exists
    } //close for loop
    else
    comments.append("Save command cancelled by user." + newline);
    } // end-if save button
    } // close method actionPerformed
    } //close constructor CenterPanel
    } // Closes class CenterPanel

    There is no way to be able to see MyDocumentListener class in the way you wrote. The reason is because MyDocumentListener class inside the constructor itself. MyDocumentListener class is an inner class, not suppose to be inside a constructor or a method. What you need to do is simple thing, just move it from inside the constructor and place it between two methods.
    that's all folks
    Qusay

  • "cannot resolve symbol" help..

    Here is a very short and simpel program that won't compile after I reinstalled java on my computer.
    import java.lang.Math.*;
    import java.awt.*;
    public class PiTest extends Frame {
         public static void main(String[] p){
         System.out.println("testing MATHs");
         System.out.println(""+sin(10));
    I get the following error:
    PiTest.java:8: cannot resolve symbol
    symbol : method sin (int)
    location: class PiTest
    System.out.println(""+sin(10));
    ^
    [total 1553ms]
    1 error
    Why doesn't the compiler recognise the sine function? I have set my classpath to c:\j2sdk1.4.1_01\lib.
    I don't know what I'm doing wrong...

    Replace sin(10) with Math.sin(10), it should work.
    import java.lang.Math.*;
    import java.awt.*;
    public class PiTest extends Frame {
    public static void main(String[] p){
    System.out.println("testing MATHs");
    //System.out.println(""+sin(10));
    System.out.println(""+Math.sin(10));

Maybe you are looking for

  • Stream from time capsule to applte tv via ipad air

    hi, im pretty new with apple...i used android before but im thinking about a change.... i want to stream music and movies/photos from a time capsule to tv and an av receiver via an ipad air. is that possible? do i need a special app? if so, how do i

  • What is needed for a PC user to video chat with me on ichat?

    I'm a newbie at this....The easiest solution is to convert them to MAC! But that isn't going to happen! Desperately need to see my little grandson.....please help if you can.....the answer is probably very simple and i am going to feel a little silly

  • Debug aplication started using ant

    Hello, I wonder if it is possible to stop and debug an aplication in a breakpoint when this aplication was started using ant from eclipse as IDE. I use eclipse ver. 3.0. thanks a lot for any help or ideea

  • TS3992 The last backup could not be completed. iCloud Help?

    Since 7/9/2012 my iPad has giving me a message that said "The last backup could not be completed". I've had iCloud since it come out. I have never had this problem.

  • Set user status

    Hi, I am using the BAPI_SALESORDER_CREATEFROMDAT2 to create a sale order. I am looking for a function module to set the user status to "VALIDATE"  after the excution the previous bapi. Could you help me? Abdel