Well, im just trying to make some images appear in a JWindow, just for practice
If i add some right-clicks inside the window then it will give an option whether to close the window (terminating the application that is) or not, so far that was solved by using a JOptionPane
I also want if i do left-click inside the window, there would be a choice just like the usual left click menu, containing properties and some other custom choices which i might insert later
Though, i havent find any way to process whether the MouseEvent input is a left or right click, anybody know how?
Bout the mouseDrag problem, i want to make it that if i mousePressed and drag the window, the window would follow according to where i dragged it, just like if u drag a frame, but in JWindow i cant seem to drag it at all
Actually, none of the MouseMotionListener implementation worked at all, the mouseMoved itself that Mr. levent said to send a MouseEvent simply by hovering above the component doesn't work even when i move my mouse inside the window
Bit troubled here, anybody experienced with JWindow could help me?
here's the code so far, just a simple one
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
public class Anima2 implements MouseListener,MouseMotionListener
{
JWindow w;
public static void main(String[] args) throws MalformedURLException
{
String path = <Path where the image is located, i used a gif btw>;
Anima2 a = new Anima2(path);
}
public Anima2(String path) throws MalformedURLException
{
URL url = new URL(path);
Icon icon = new ImageIcon(url);
JLabel label = new JLabel(icon);
w = new JWindow();
w.addMouseListener(this);
w.getContentPane().add(label);
w.pack();
w.setLocationRelativeTo(null);
w.setVisible(true);
}
public void mousePressed(MouseEvent e)
{
System.out.println("Mouse Pressed");
}
public void mouseReleased(MouseEvent e)
{
System.out.println("Mouse Released");
}
public void mouseClicked(MouseEvent e)
{
System.out.println("Mouse Clicked");
JOptionPane j = new JOptionPane();
int i = j.showConfirmDialog(null,"Close?");
if(i == 0)
System.exit(0);
}
public void mouseEntered(MouseEvent e)
{
System.out.println("Entering Window");
}
public void mouseExited(MouseEvent e)
{
System.out.println("Leaving Window");
}
//these 2 methods below doesnt work at all
public void mouseDragged(MouseEvent e)
{
System.out.println("Dragged");
}
public void mouseMoved(MouseEvent e)
{
System.out.println("Moved");
}
}