i've got problem program can't solve. i'm trying hours , tried google, etc... i've seen many programs, working, don't know why solution not. goal (for now) simple, want write cmd-line in case of mouse click or key press. first 1 works, second not. can tell why?
import java.awt.eventqueue; import javax.swing.jframe; import java.awt.event.keyadapter; import java.awt.event.keyevent; import java.awt.event.mouseadapter; import java.awt.event.mouseevent; public class test { private jframe frame; public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { try { test window = new test(); window.frame.setvisible(true); } catch (exception e) { e.printstacktrace(); } } }); } public test() { initialize(); } private void initialize() { frame = new jframe(); frame.getcontentpane().addmouselistener(new mouseadapter() { @override public void mouseclicked(mouseevent arg0) { system.out.println("mouse has clicked!"); } }); frame.getcontentpane().addkeylistener(new keyadapter() { @override public void keypressed(keyevent arg0) { system.out.println("a key has pressed."); } }); frame.setbounds(100, 100, 450, 300); frame.setdefaultcloseoperation(jframe.exit_on_close); } }
well, had enough time trying find solution , i'm discovered it. not know why, not possible add keylistener jframe. add jbutton or jtextfield, etc... strange me, little bit :c
Comments
Post a Comment