troubleshooting Question

Images and jsliders :S

Avatar of idunnootje
idunnootje asked on
7 Comments1 Solution215 ViewsLast Modified:

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.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);
          try {
          catch(InterruptedException e) {
          mt2 = new MediaTracker(this);
          try {
          catch(InterruptedException e) {
     public void destroy() {
     public void paint(Graphics g) {
     case 1:
     img1 = getImage(getDocumentBase(),"red.jpg");
     System.out.println("Panorama getekend.");
     case 2:
     img1 = getImage(getDocumentBase(),"blue.jpg");
     img1 = getImage(getDocumentBase(),"red.jpg");
     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){
     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:

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:

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.


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