Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying an image and painting over it

Status
Not open for further replies.

juanfd

IS-IT--Management
Jan 21, 2004
45
Hello I've been trying to creat a mini Paint application but so far all i can do is load an image, display it and apply some effects on it.
I need to be able to paint circles, rectangles, etc over it and then save it wih the new stroke i've drawn.
I'm using DisplayJAI in order to display the image, but as I try to override the mouseClicked, mouseEntered, etc. methods, they just don't do anything. After step by step debugging I found that the programm never goes through these lines of code, no matter what. Maybe I'm missing soething. any help is greatly appreciated.

The code I am using:
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.io.*;
import javax.media.jai.*;
import javax.swing.*;
import com.sun.media.jai.widget.DisplayJAI;

public class imageDisplay extends DisplayJAI {
public imageDisplay(PlanarImage image){
this.set(image);
}

public void mouseClicked(MouseEvent me){
System.out.println("hola clic");
}

public void mouseEntered(MouseEvent me){
System.out.println("hola enter");
}

public void mouseExited(MouseEvent me){
System.out.println("hola exit");
}

public void mousePressed(MouseEvent me){
System.out.println("hola press");
}

public void mouseReleased(MouseEvent me){
System.out.println("hola release");
}

public void mouseDragged(MouseEvent me){
System.out.println("hola dragg");
}

public void mouseMoved(MouseEvent me){
System.out.println("hola move");
}
}

and to display the image on a JScrollPane:

display = new imageDisplay(image);
imagePanel.add(new JScrollPane(display),BorderLayout.CENTER);
imagePanel.validate();

thanks a lot!
 
Well your class needs to :

- implement the MouseListener class, ie :

public MyClass implements MouseListener, extends DisplayJAI

- You need to register your class as the mouse listener with your display component (ie JFrame of whatever), ie :

JFrame myJFrame = new JFrame();
myJFrame.addMouseListener(this);

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top