Results 1 to 3 of 3
  1. #1
    Manojx is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

    Exclamation Can anyone say how to fix this error read this problem

    Hi to all

    here i have been trying to create button with image in which it gets image from a source.
    so simply at the beginning i tried create button with BOXICON where the a image appears on the BOXICON so that it seems like as image appears next to the button.

    anyhow i executed the code and solved some of the error but here at last i kept getting an error message
    Now i don't know what to do and i even tried many searches on Google and nothing found useful

    Can anyone tell me how to solve this
    ERROR MESSAGE

    C:\components>javac ButtonwithImageIcon.java
    ButtonwithImageIcon.java:86: cannot find symbol
    symbol : method drawImage(java.awt.Image,int,int,BoxIcon)
    location: class java.awt.Graphics
    g.drawImage(img,6,0,this);
    ^
    1 error

    here is my code as follows :
    Java Code:
    import java.awt.*;
    import java.io.*;
    import javax.swing.*; 
    import javax.imageio.*;
    
    /*
    <applet code="ButtonwithImageIcon.class" width=350 height=100></applet>
    */
    
    
    public class ButtonwithImageIcon extends JFrame 
    {
    
      public static void main(String[] args) 
    {
        ButtonwithImageIcon that = new ButtonwithImageIcon();
        that.setVisible(true);
      }
    
    
      public ButtonwithImageIcon()
    
     {
        setSize(450, 350);  
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        getContentPane().add(new ButtonPanel(), BorderLayout.SOUTH);
    
        
        
      }
    }
    
    class ButtonPanel extends JPanel {
    
      public ButtonPanel()
      {
    
        JButton btn = new JButton("Title 1", new BoxIcon( 1)); 
         
        btn.setHorizontalTextPosition(JButton.RIGHT);
         btn.setBorder(BorderFactory.createEtchedBorder()); 
          
        add(btn);
      
        GCanvas canvas=new GCanvas();
        setVisible(true);
      }
    
    
    }
    
    
    class BoxIcon implements Icon 
    
    {
      
    
      private int borderWidth;
    
      BoxIcon( int borderWidth) {
        
        this.borderWidth = borderWidth;
      }
    
      public int getIconWidth() {
        return 20;
      }
    
      public int getIconHeight() {
        return 20;
      }
    
    
      public void paintIcon(Component c, Graphics g, int x, int y)
     {
         Image img = null;
    
    	try 
               {
                 img=ImageIO.read(new File("bin/right.png"));}
      
            catch
                 (IOException e){System.out.println("ok");System.exit(0);}
      
         g.drawImage(img,6,0,this);
        g.fillRect(x, y, getIconWidth(), getIconHeight());
           
      }
    
    
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,314
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by Manojx View Post
    Can anyone tell me how to solve this
    ERROR MESSAGE

    C:\components>javac ButtonwithImageIcon.java
    ButtonwithImageIcon.java:86: cannot find symbol
    symbol : method drawImage(java.awt.Image,int,int,BoxIcon)
    location: class java.awt.Graphics
    g.drawImage(img,6,0,this);
    ^
    1 error
    Carefully read the error message: your compiler is trying to tell you that it can't find a method drawImage that takes parameters java.awt.Image,int,int,BoxIcon. Now read the API documentation for the Graphics class and see that your compiler is right.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    6

    Default

    Usually when I get that error (cannot find symbol) it is because I have fed the wrong TYPE of parameters

    method drawImage(java.awt.Image,int,int,BoxIcon)
    g.drawImage(img,6,0,this);

    according to the Java API, the drawImage method has this implementation which is closest to what you tried to call:

    drawImage(Image img, int x, int y, ImageObserver observer)

    so I would suspect that BoxIcon is not of the type ImageObserver

Similar Threads

  1. File Read Problem
    By Indegon in forum New To Java
    Replies: 6
    Last Post: 01-25-2011, 03:56 PM
  2. Error printing from Read in file.
    By Accendo in forum New To Java
    Replies: 6
    Last Post: 01-21-2011, 07:07 AM
  3. JTextField Array Read Error
    By relax1 in forum New To Java
    Replies: 6
    Last Post: 12-17-2010, 10:30 PM
  4. Problem with C.read
    By JavaAssistance in forum New To Java
    Replies: 1
    Last Post: 10-07-2010, 03:15 AM
  5. System.in.read(); strange error!
    By kantze in forum New To Java
    Replies: 2
    Last Post: 03-19-2008, 02:44 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
  •