Created
September 22, 2012 06:09
-
-
Save TonyWhite/3765316 to your computer and use it in GitHub Desktop.
MarioMouse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.datatransfer.*; | |
| import java.awt.*; | |
| public class JClipboard implements ClipboardOwner | |
| { | |
| /** | |
| * Incolla nella Clipboard | |
| */ | |
| public void toClipboard(String contenuto) | |
| { | |
| StringSelection st = new StringSelection(contenuto); | |
| Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard(); | |
| cp.setContents(st, this); | |
| } | |
| /** | |
| * Legge il testo dalla clipboard di sistema | |
| */ | |
| public String fromClipboard() | |
| { | |
| String contenuto = null; | |
| Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard(); | |
| Transferable contents = cp.getContents(null); | |
| boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor); //Se c'è il contenuto ed è una stringa | |
| if (hasTransferableText) | |
| { | |
| try | |
| { | |
| contenuto = (String)contents.getTransferData(DataFlavor.stringFlavor); | |
| } | |
| catch(Exception e){} | |
| } | |
| return contenuto; | |
| } | |
| public void lostOwnership(Clipboard clip, Transferable tr){} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Il mouse che arriva sul bordo dello schermo, poi si ritrova sul bordo opposto. | |
| * | |
| * | |
| * Autore: Antonio Bianco | |
| * Versione: |0| | |
| */ | |
| import java.awt.Dimension; | |
| import java.awt.Toolkit; | |
| import java.awt.Robot; // Controlla il mouse | |
| import java.awt.MouseInfo; // Leggi le informazioni del mouse | |
| import java.awt.PointerInfo; | |
| import java.awt.Point; | |
| public class MarioMouse extends Thread | |
| { | |
| // instance variables - replace the example below with your own | |
| private Robot r; | |
| private boolean scassaLePalle; | |
| private JClipboard clipboard; | |
| public static void main(String args[]) | |
| { | |
| new MarioMouse(); | |
| } | |
| /** | |
| * Constructor for objects of class MarioMouse | |
| */ | |
| public MarioMouse() | |
| { | |
| super("MarioMouse"); | |
| try | |
| { | |
| r = new Robot(); | |
| scassaLePalle = true; | |
| clipboard = new JClipboard(); | |
| clipboard.toClipboard(""); | |
| } | |
| catch (Exception e) | |
| { | |
| System.out.println("Impossibile inizializzare la classe Robot.\nProkramma kapùtt"); | |
| System.exit(1); | |
| } | |
| this.start(); | |
| } | |
| public void run() | |
| { | |
| while(scassaLePalle) | |
| { | |
| try | |
| { | |
| // Legge la dimensione del desktop | |
| Dimension dimensioniSchermo = Toolkit.getDefaultToolkit().getScreenSize(); // Legge le dimensioni dello schermo | |
| int maxX = dimensioniSchermo.width - 1; | |
| int maxY = dimensioniSchermo.height - 1; | |
| // Legge la posizione attuale del mouse | |
| PointerInfo info = MouseInfo.getPointerInfo(); | |
| Point punto = info.getLocation(); | |
| int x = (int)punto.getX(); | |
| int y = (int)punto.getY(); | |
| if ((x==maxX)||(y==maxY)||(x==0)||(y==0)) | |
| { | |
| if (x==maxX) x=1; | |
| if (y==maxY) y=1; | |
| if (x==0) x=maxX-1; | |
| if (y==0) y=maxY-1; | |
| r.mouseMove(x, y); | |
| } | |
| // Esce dall'applicazione | |
| if (clipboard.fromClipboard().equals("Geek rulez")) System.exit(0); | |
| Thread.sleep(1); | |
| } | |
| catch(Exception e) | |
| { | |
| // Nope | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment