Created
January 18, 2013 20:22
-
-
Save dgreensp/4568193 to your computer and use it in GitHub Desktop.
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.Dimension; | |
import java.awt.Toolkit; | |
import java.awt.event.MouseEvent; | |
import java.awt.event.MouseMotionListener; | |
import javax.swing.JFrame; | |
public class blank implements Runnable, java.awt.event.MouseListener, MouseMotionListener | |
{ | |
int SIZE; | |
JFrame frame; | |
int xoff; | |
int yoff; | |
int bumpx = -1; | |
int bumpy = -1; | |
static int[] data = { 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; | |
public void run() { | |
this.frame = new JFrame(); | |
this.frame.setDefaultCloseOperation(3); | |
Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize(); | |
this.SIZE = Math.min(localDimension.width / 8, localDimension.height / 5); | |
this.frame.setSize(this.SIZE, this.SIZE); | |
this.frame.setUndecorated(true); | |
this.frame.setVisible(true); | |
this.frame.addMouseListener(this); | |
this.frame.addMouseMotionListener(this); | |
} | |
public void mouseClicked(MouseEvent paramMouseEvent) {} | |
public void mousePressed(MouseEvent paramMouseEvent) | |
{ | |
this.xoff = paramMouseEvent.getX(); | |
this.yoff = paramMouseEvent.getY(); | |
} | |
public void mouseReleased(MouseEvent paramMouseEvent) {} | |
public void mouseEntered(MouseEvent paramMouseEvent) {} | |
public void mouseExited(MouseEvent paramMouseEvent) {} | |
public int signum(int paramInt) | |
{ | |
if (paramInt < 0) | |
return -1; | |
if (paramInt > 0) { | |
return 1; | |
} | |
return 0; | |
} | |
public void mouseDragged(MouseEvent paramMouseEvent) { | |
int i = paramMouseEvent.getXOnScreen(); | |
int j = paramMouseEvent.getYOnScreen(); | |
int k = (i - paramMouseEvent.getX()) / this.SIZE; | |
int m = (j - paramMouseEvent.getY()) / this.SIZE; | |
int n; | |
int i1; if ((k >= 0) && (k < 8) && (m >= 0) && (m < 5) && (data[(k * 5 + m)] != 0)) { | |
int i2 = (i - paramMouseEvent.getX()) % this.SIZE; | |
int i3 = (j - paramMouseEvent.getY()) % this.SIZE; | |
int i4 = Math.min(i2, this.SIZE - 1 - i2); | |
int i5 = Math.min(i3, this.SIZE - 1 - i3); | |
int i6 = paramMouseEvent.getX() - this.xoff; | |
int i7 = paramMouseEvent.getY() - this.yoff; | |
if (Math.abs(i6) > i4) | |
i6 = signum(i6) * i4; | |
if (Math.abs(i7) > i5) | |
i7 = signum(i7) * i5; | |
n = this.xoff + i6; | |
i1 = this.yoff + i7; | |
} | |
else { | |
n = this.xoff; | |
i1 = this.yoff; | |
} | |
this.frame.setLocation(i - n, j - i1); | |
} | |
public void mouseMoved(MouseEvent paramMouseEvent) {} | |
public static void main(String[] paramArrayOfString) | |
{ | |
javax.swing.SwingUtilities.invokeLater(new blank()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment