So I have been trying to figure out some things with Java. I have the click event trigger and print "SUPSUP" in the program when the JFrame window pops up. But I was wondering is there a way to set up the app where if I press button 4 outside the JFrame window the "SUPSUP" will still be printed? I mean I want to have a listener in java in general not tied to the JFrame Components, I wouldn't mind if I needed to use a key listener either. I'm trying to build a program that will do certain things on the screen every time I click on button 4, but I can't be able to click on the blue JFrame thanks.
So Far I have this code.
public class CriticalMassWizard implements MouseListener
{
private static CriticalMassWizard instance = null;
private static Robot robot;
private static boolean triggerSpam;
private static JFrame frame = new JFrame("Tester");
// Singleton
public static CriticalMassWizard getInstance()
{
if(instance == null) {
instance = new CriticalMassWizard();
instance.setUpFrame();
try {
robot = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return instance;
}
private void setUpFrame()
{
frame.setResizable(true);
frame.setSize(300, 300);
frame.getContentPane().setBackground(Color.BLUE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.addMouseListener(this);
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getButton() == 4)
{
System.out.println("SUPSUP");
}
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}