Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Java MouseInputAdapter
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
copthesaint




PostPosted: Thu May 12, 2011 10:58 am   Post subject: Java MouseInputAdapter

Just Wondering if I am doing this right Razz. I made this class to open up FullScreenExclusive mode then to get the mouse properties I added MouseListener and MouseMotionListener to the frame, It works, but I am just wondering if Im doing it right lol... Also if I could get any tips that would help me alot Smile.

Java:
import java.awt.*;
   import java.awt.image.BufferStrategy;
   import java.awt.BorderLayout;
   import java.awt.Frame;
   import java.awt.event.*;
   import java.awt.GraphicsConfiguration;
   import javax.vecmath.*;
   import javax.swing.event.MouseInputAdapter;
 
   public class MouseTest {
      public static Color[] COLORS = new Color[] {Color.white,Color.black};
      public static DisplayMode[] DISPLAYMODES = new DisplayMode[]{new DisplayMode (640,440,32,60),new DisplayMode(800, 600, 32, 60), new DisplayMode (1024,768,32,60)};
      Frame mainFrame;
             
      private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
         for (int x = 0; x < DISPLAYMODES.length; x++) {       
            DisplayMode[] modes = device.getDisplayModes();
            for (int i = 0; i < modes.length; i++) {
               if (modes[i].getWidth() == DISPLAYMODES[x].getWidth()&& modes[i].getHeight() == DISPLAYMODES[x].getHeight()&& modes[i].getBitDepth() == DISPLAYMODES[x].getBitDepth()){
                  return DISPLAYMODES[x];
               }
            }
         }
         return null;
      }
     
      public static void chooseBestDisplayMode(GraphicsDevice device) {
         DisplayMode best = getBestDisplayMode(device);
         if (best != null) {
            device.setDisplayMode(best);
         }
      }
   
      public MouseTest (GraphicsDevice device) {
         try { 
            GraphicsConfiguration gc = device.getDefaultConfiguration();
            mainFrame = new Frame(gc);
            mainFrame.setUndecorated (true);
            mainFrame.setIgnoreRepaint(true);
            device.setFullScreenWindow(mainFrame);
            if (device.isDisplayChangeSupported()) {
               chooseBestDisplayMode(device);
            }
            Rectangle bounds = mainFrame.getBounds ();
            MouseListenerTest testMouse = new MouseListenerTest(mainFrame);
            mainFrame.createBufferStrategy(2);
            BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();
            Graphics g = bufferStrategy.getDrawGraphics();
         
         
         }
            catch (Exception e) {
               e.printStackTrace();
            } 
         finally {
            device.setFullScreenWindow (null);
         }
     
      } 
        
      public static void main (String[] args){
         try {
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice device = env.getDefaultScreenDevice();
            MouseTest test = new MouseTest(device);
         }
            catch (Exception e) {
               e.printStackTrace();
            }
         System.exit(0);
     
      }
   
      public class MouseListenerTest extends MouseInputAdapter {
         public MouseListenerTest (Frame f) {
            f.addMouseListener(this);
            f.addMouseMotionListener(this);
         }
     
         public void mousePressed(MouseEvent e) {
            int x = e.getX();
            int y = e.getY();
            System.out.println (x + ":" + y);
         }
     
         public void mouseMoved(MouseEvent e) {
           
         }
     
         public void mouseDragged(MouseEvent e) {
           
         }
     
         public void mouseClicked(MouseEvent e) {
         }
     
         public void mouseEntered(MouseEvent e) {
           
         }
     
         public void mouseExited(MouseEvent e) {
           
         }
     
         public void mouseReleased(MouseEvent e) {
           
         }
     
     
      }
   
   
   }
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: