sparkx 0 Report post Posted September 14, 2008 This question is not as easy as you may think to answer, so please read my post completely before replying. I am trying to make an applet that responds to mouse movements but I always have trouble. I can make it work just fine if I find the distance from a point using getX(); or getXOnScreen(); but that's not what I want to do. I want to get the direct input from the mouse. Why? Because when the mouse (cursor) hits the edge of the screen its position stays the same even when you move it. I have tried using a robot to keep the mouse in the center of the screen (setPosition or something like that). But that is just glitch because the robot no longer works when the cursor leaves the window. One possible solution that I haven't gotten to work yet is full screen mode (as in actually full screen not just maximized). This would also solve the problem of accidentally clicking things in the background (not on the game). Any Suggestions?Please post/link to tutorials, source and/or documentation.Thanks, Sparkx Share this post Link to post Share on other sites
wutske 0 Report post Posted September 16, 2008 This question is not as easy as you may think to answer, so please read my post completely before replying.  I am trying to make an applet that responds to mouse movements but I always have trouble. I can make it work just fine if I find the distance from a point using getX(); or getXOnScreen(); but that's not what I want to do. I want to get the direct input from the mouse. Why? Because when the mouse (cursor) hits the edge of the screen its position stays the same even when you move it. I have tried using a robot to keep the mouse in the center of the screen (setPosition or something like that). But that is just glitch because the robot no longer works when the cursor leaves the window. One possible solution that I haven't gotten to work yet is full screen mode (as in actually full screen not just maximized). This would also solve the problem of accidentally clicking things in the background (not on the game). Any Suggestions?Please post/link to tutorials, source and/or documentation.Thanks, Sparkx The listner probably receives wrong values when the mouse leaves the screen, see if it throws an error. Share this post Link to post Share on other sites
sparkx 0 Report post Posted September 24, 2008 That’s not the problem though... You know when your cursor hits the edge of the screen you can't move it any more? Well that makes a problem for me (because you can continue to move the mouse itself just not the cursor). All I am interested in is the direct input from the mouse not the location of the cursor. I don't want the "coded" input that limits the mouse to inside the screen. Here is an example... you want to move an object lets say a square that is in the center of the java applet. The applet also has a background image (keep in mind it is all 2d so it is simple). To move the square you would click on it and move the mouse, the background would move the opposite direction of the input from the mouse (giving the affect that the square is moving in that direction but it is not actually moving compared to the screen and centered in the applet). This is simple to do but you quickly run into a problem. The cursor is at the edge of the screen but the square is still not were you want it. See the problem?Any Suggestions?Thanks,Sparkx Share this post Link to post Share on other sites
iGuest 3 Report post Posted September 23, 2010 import java.Awt.*;Import javax.Swing.*;public abstract class dragon { private static DisplayMode modes[] = { new DisplayMode(800,600,32,0), new DisplayMode(800,600,24,0), new DisplayMode(800,600,16,0), new DisplayMode(640,480,32,0), new DisplayMode(640,480,24,0), new DisplayMode(640,480,16,0), }; private boolean running; protected ScreenManager s; //stop method public void stop(){ running = false; } //call init and gameloop public void run(){ try{ init(); gameLoop(); }finally{ s.RestoreScreen(); } } //set to full screen public void init(){ s = new ScreenManager(); DisplayMode dm = s.FindfirstCompatibleMode(modes); s.SetfullScreen(dm); Window w = s.GetFullScreenWindow(); w.SetFont(new Font("Arial", Font.PLAIN,20)); w.SetBackground(Color.GREEN); w.SetForeground(Color.WHITE); running = true; } //main movie loop public void gameLoop(){ long startTime = System.CurrentTimeMillis(); long cumTime = startTime; while(running){ long timePassed = System.CurrentTimeMillis() - cumTime; cumTime =+ timePassed; update(timePassed); Graphics2D g =s.GetGraphics(); draw(g); g.Dispose(); s.Update(); try{ Thread.Sleep(20); }catch(Exception ex){} } } //update animation public void update(long timePassed){ } //draw public abstract void draw(Graphics2D g); } this is a full screen and just main things u use on every java program draw animation res for monitor move loop and things like that copy this and it will help u a little it's all commented so with the moving across screen non stop it's java.Awt.Robot Share this post Link to post Share on other sites