troubleshooting Question

Images and jsliders :S

Avatar of idunnootje
idunnootje asked on
Java
7 Comments1 Solution215 ViewsLast Modified:
Hi,

i'm a beginner in programming in Java and i seem to be a bit stuck.
I'm trying to create an applet in which 2 pictures are shown. If you click the picture in the upper left corner, it should change into an other picture. This works fine.
But, i also want to use a slider! (I don't even know if this is possible,  for i am a beginner).

The source code without the slider is:

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.net.*;
import java.applet.*;

public class panorama extends java.applet.Applet implements MouseListener{
     int status;     //1=turn into red 2=turn into blue
     Image img1, blue, red, panorama;
     MediaTracker mt1, mt2;
     public void init() {
          blue = getImage(getDocumentBase(),"blue.jpg"); //width = 74 height = 72
          red = getImage(getDocumentBase(),"red.jpg");
          panorama = getImage(getDocumentBase(),"Panorama.gif");
          img1 = blue;     //veranderd in rood
          status = 1;
          mt1 = new MediaTracker(this);
          mt1.addImage(img1,0);
          try {
               mt1.waitForAll();
          }
          catch(InterruptedException e) {
               e.printStackTrace();
          }
          mt2 = new MediaTracker(this);
          mt2.addImage(panorama,0);
          try {
               mt2.waitForAll();
          }
          catch(InterruptedException e) {
               e.printStackTrace();
          }
          addMouseListener(this);
     }
     public void destroy() {
        removeMouseListener(this);
     }
     public void paint(Graphics g) {
     switch(status){
     case 1:
     img1 = getImage(getDocumentBase(),"red.jpg");
     g.drawImage(panorama,0,0,this);
     System.out.println("Panorama getekend.");
     g.drawImage(img1,0,0,this);
     status=2;
     break;
     case 2:
     img1 = getImage(getDocumentBase(),"blue.jpg");
     g.drawImage(panorama,0,0,this);
     g.drawImage(img1,0,0,this);
     status=1;
     break;
     default:
     img1 = getImage(getDocumentBase(),"red.jpg");
     g.drawImage(panorama,0,0,this);
     g.drawImage(img1,0,0,this);
     status=0;
     }
     }
     public void mouseReleased(MouseEvent e) {
     System.out.println("In Change.mouseReleased");
     int x = e.getX();
     int y = e.getY();
     if(x>0 && x<74 && y>0 && y<72){
          repaint();
          }
     }
     public void mousePressed(MouseEvent e) {
     System.out.println("In Change.mousePressed");
     }
     public void mouseClicked(MouseEvent e) {
     System.out.println("In Change.mouseClicked");
     }
     public void mouseEntered(MouseEvent e) {
     System.out.println("In Change.mouseEntered");
     }
     public void mouseExited(MouseEvent e) {
     System.out.println("In Change.mouseExited");
     }
}

The pictures red.jpg & blue.jpg are basic images (74x72) made in paint. Panorama.gif can be found at: http://www.olympia360.com/art/Panorama.gif

Now i want to add a slider (is it possible to put it anywhere i want?). I thought i could use parts of the following source code: http://grace.evergreen.edu/artofcomp/examples/Slider2.php

I placed the lines from JSlider slider = new JSlider(... through pane.add(slider); after addMouseListener(this); in my own source. I left out the changelistener and the counter. I also importet javax.swing.*; and javax.swing.event.*;.....

This doesn't work, because i get a compiling error at this.getContentPane():
cannot resolve symbol
symbol  : method getContentPane()
location: class panorama
       Container pane = this.getContentPane();
                             ^ (under the 'g')

I guess these are basic errors but as a beginner i seem to be a bit stuck here. So, can somebody help me? Thanks.

Idunnootje.
ASKER CERTIFIED SOLUTION
heyhey_

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros