0

So I know I suck at programming, but if anyone could give me some code help I would appreciate it, I don't know why I am getting this error

cannot find symbol

  g.drawImage(movPic2, 35, 515, 200, 200,this);                 ^
  symbol:   variable movPic2
  location: class MovieDis

if any1 could give me a code snippet example i have trouble understanding in just words. tired of this program and just wanting to get done with it.

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

public class Movie extends JApplet {

    private String movName1;
    private String director1;
    private int yearMade1;
    private Image movPic1;
    private String movName2;
    private String director2;
    private int yearMade2;
    private Image movPic2;
    private String movName3;
    private String director3;
    private int yearMade3;
    private Image movPic3;
    private String movName4;
    private String director4;
    private int yearMade4;
    private Image movPic4;

    public void init() {
        MovieDis goo = new MovieDis(movPic1, movPic2, movPic3, movPic4);
        goo.setBounds(0, 0, 750, 500);
        add(goo);
    }
}

class MovieDis extends JComponent {

    private String movName1;
    private String director1;
    private int yearMade1;
    private Image movPic1;
    private String movName2;
    private String director2;
    private int yearMade2;
    private Image movPic2;
    private String movName3;
    private String director3;
    private int yearMade3;
    private Image movPic3;
    private String movName4;
    private String director4;
    private int yearMade4;
    private Image movPic4;

    public MovieDis(Image movPic1, Image movPic2, Image movPic3, Image movPic4) {
        setBackground(Color.black);
        movPic1 = Toolkit.getDefaultToolkit().createImage("Shaw.jpg");
        movPic2 = Toolkit.getDefaultToolkit().createImage("dances.jpg");
        movPic3 = Toolkit.getDefaultToolkit().getImage("Inception.jpg");
        movPic4 = Toolkit.getDefaultToolkit().getImage("Cuckoo.jpg");
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);
        g.fillRect(0, 0, 750, 500);
        g.drawImage(movPic1, 35, 35, 200, 200, this);
        g.drawImage(movPic2, 35, 515, 200, 200, this);
        g.drawImage(movPic3, 265, 35, 200, 200, this);
        g.drawImage(movPic4, 35, 515, 200, 200, this);
    }
}
hrittwik
  • 21
  • 1
  • 13

1 Answers1

2

the variable movPic1 (and 2-4) are not stored anywhere inside your MovieDis class. That's why the paintComponent() method is complaining. You need to add those to MovieDis and then assign them in your class constructor.

Dan O
  • 6,022
  • 2
  • 32
  • 50
  • hey this worked. thank you, i am still having a problem creating the images though, it gets to g.fillRect(0,0,750,500); and it doesnt draw the images it seems, is it something wrong with how i stored them in MovieDis constructor? – user1547182 Aug 10 '12 at 23:33
  • could you edit your question and update it to contain your new code? thanks. – Dan O Aug 10 '12 at 23:37
  • @user1547182: that seems like a new question. Consider 1+ orzechowskid's answer (as I have done), accepting it, and asking a new question. – Hovercraft Full Of Eels Aug 10 '12 at 23:48
  • it requires 15 reputation. also i re edited my code orzechowskid, i hope i didnt do anything code illegal or bad, but i basically restated the variables in the second class because i didnt really use them in first – user1547182 Aug 10 '12 at 23:59
  • I just answered this question http://stackoverflow.com/questions/11910783/images-are-not-showing-up-in-paint-component :( – MadProgrammer Aug 11 '12 at 02:20