Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pacote;
- import java.awt.Toolkit;
- import javax.swing.JFrame;
- public class Classinha {
- public static void main(String[] args) {
- JFrame j = new JFrame("janelinhaaaa");
- j.setSize(300,300); j.setVisible(true); j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);j.setResizable(false);
- double d = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
- double d2 = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
- int up = 0;int right = 0;int rb = 0;int ub = 0;
- while (true) {
- //System.out.println(j.getLocation()+" "+d+" "+d2+ " "+up+" "+right);
- int x = j.getLocation().x;
- int y = j.getLocation().y;
- if (x == 0 && y == 0) {
- up = 1;right = 1;ub = 1;rb = 1;
- while (cdt(x,y,up,right)) {
- j.setLocation(x + right, y + up);
- x = j.getLocation().x;
- y = j.getLocation().y;
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println(1+" "+j.getLocation()+" "+d+" "+d2+" "+up+" "+right);
- }
- } else if (y == 468 && x != 1066) {
- up = -ub;
- while (cdt(x,y,up,right)) {
- j.setLocation(x + right, y + up);
- x = j.getLocation().x;
- y = j.getLocation().y;
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println(2+" "+j.getLocation()+" "+d+" "+d2+" "+up+" "+right);
- }
- } else if (y == 0) {
- up = -ub;
- while (cdt(x,y,up,right)) {
- j.setLocation(x + right, y + up);
- x = j.getLocation().x;
- y = j.getLocation().y;
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println(3+" "+j.getLocation()+" "+d+" "+d2+" "+up+" "+right);
- }
- } else if (x == 1066) {
- right = - rb;
- while (cdt(x,y,up,right)) {
- j.setLocation(x + right, y + up);
- x = j.getLocation().x;
- y = j.getLocation().y;
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println(4+" "+j.getLocation()+" "+d+" "+d2+" "+up+" "+right);
- }
- } else if (x == 0) {
- right = - rb;
- while (cdt(x,y,up,right)) {
- j.setLocation(x + right, y + up);
- x = j.getLocation().x;
- y = j.getLocation().y;
- try {
- Thread.sleep(5);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println(4+" "+j.getLocation()+" "+d+" "+d2+" "+up+" "+right);
- }
- }
- rb = right;ub = up;
- }
- }
- public static boolean cdt(int x,int y,int uu,int rr) {
- if (x == 0 && y == 0) {
- return true;
- }
- if (rr == 1 && uu == 1) {
- return x<1066 && y<468;
- } else if (rr == -1 && uu == 1) {
- return x > 0 && y < 468;
- } else if (rr == 1 && uu == -1) {
- return x<1066 && y>0;
- } else if (rr == -1 && uu == -1) {
- return x > 0 && y>0;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement