Hey guys i am struggling a bit with Jframe.Pretty new to JFrame.
I hav a file in Picture class and need to bring the BufferedImage to the DrawingImageControlPanel.How do i do this.
I know the template for doing this is as stated below.

public class ClassName
    extends JPanel {

      instance variable declarations

      helper methods

      public constructors

      public methods for communication

      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        drawing messages sent to g
      }

    }

Here is the code in Picture Class that i need to invoke

/**
   * Constructor that takes a buffered image
   * @param image the buffered image to use
   */
  public Picture(BufferedImage image)
  {
    super(image);
  }

Below is my code for Just the class DrawDrawingImageControlPanel

class DrawImageControlPanel extends JPanel
  { 

    // Get Image
public DrawImageControlPanel () 
{
  BufferedImage beach;
  public DrawImageControlPanel (){ //**Complier say illegal start of expression and expected ';'**
    beach=image;
  }
}


    // Draw Image into BufferedImage
    public void paintComponent(Graphics g)  
    {
      super.paintComponent(g);// invoke the superclass paintComponent
      paintComponent BufferedImage  = picture.getBufferedImage(); // **Complier says expected';'**
      Graphics2D g2 = (Graphics2D) g;
      g2.drawImage(Image, null, 0 , 0);
      }

  }
}

Thank you

Recommended Answers

All 3 Replies

Line 8 seems to be the start of a method definition, but it's inside another method definition (starting line 5), which is illegal.
Lin 18 you have name followed by type (eg i int) when it should be the other way round (eg int i)

ok..below is my full code but why doesnt the complier prompt me for method definition in line 10 but does so in line 42 ?

mport java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

public class DrawControlPanel extends JPanel
{
  private Color fillColor = Color.CYAN;
  private int ovalWidth = 90;

  public DrawControlPanel()
  {
    setSize( 200, 200 ); 
  }

  public void paintComponent( Graphics g )
  {
    super.paintComponent( g );  // invoke the superclass paintComponent
    this.setBackground( Color.WHITE );
    g.setColor( fillColor );
    g.fillOval( 50, 50, ovalWidth, 60 );
  }

  void setFillColor(Color fillColor)
  {
    this.fillColor = fillColor;  
  }    

  void setOvalWidth(int ovalWidth)
  {
    this.ovalWidth = ovalWidth;  
  }  

  int getOvalWidth()
  {
    return ovalWidth;  
  }  

  class DrawImageControlPanel extends JPanel
  { 
    BufferedImage theBeach;
    // Get Image
    public DrawImageControlPanel ()
    {
      setSize(600,600);
      theBeach=image;
    }



    // Draw Image into BufferedImage
    public void paintComponent(Graphics g)  
    {
      super.paintComponent(g);// invoke the superclass paintComponent
      paintComponent BufferedImage image = picture.getBufferedImage(); // **still error **
      Graphics2D g2 = (Graphics2D) g;
      g2.drawImage(Image, null, 0 , 0);
      }

  }
}

Please post the full text of the compiler's error messages so we can see what it is saying.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.