Skip to content

Instantly share code, notes, and snippets.

@DenWav
Created November 3, 2015 04:34
Show Gist options
  • Save DenWav/2c4f5991c464227ca492 to your computer and use it in GitHub Desktop.
Save DenWav/2c4f5991c464227ca492 to your computer and use it in GitHub Desktop.
wat.jpg
private Position getPosition(JLabel label) {
// This method is proof I am an idiot
String text = "";
Class<BoardGUI> clazz = BoardGUI.class;
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.getDeclaringClass() == JLabel.class) {
try {
if (field.get(this) == label) {
text = field.getName();
}
} catch (IllegalAccessException ignored) {/*won't happen*/}
}
}
int x = Integer.parseInt(text.substring(3, 4));
int y = Integer.parseInt(text.substring(4, 5));
return new Position(x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment