Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. private void GUI()
  2. {
  3. JFrame frame = new JFrame();
  4. frame.setLayout(new MigLayout());
  5.  
  6. try
  7. {
  8. mapImg = ImageIO.read(new File("Res/Zipzone map of the US.png"));
  9. }
  10. catch (IOException e)
  11. {
  12. e.printStackTrace();
  13. }
  14. g = mapImg.createGraphics();
  15.  
  16. for(int i = 311; i < 1001; i++)
  17. {
  18. Random rand = new Random();
  19. String count = "";
  20. int red = rand.nextInt(220) + 25;
  21. int green = rand.nextInt(220) + 25;
  22. int blue = rand.nextInt(220) + 25;
  23. if(i < 100)
  24. {
  25. count = "0" + i;
  26. }
  27. else
  28. {
  29. count = i + "";
  30. }
  31. if(i <= 512)
  32. {
  33. ApplyColor(count, new Color(red, blue, green));
  34. }
  35. else if( i > 909)
  36. {
  37. ApplyColor3(count, new Color(red, blue, green));
  38. }
  39. else
  40. {
  41. ApplyColor2(count, new Color(red, blue, green));
  42. }
  43. }
  44.  
  45. frame.add(new JLabel("", new ImageIcon(GetScaledImage(new ImageIcon(mapImg).getImage(), 1400, 875)), JLabel.CENTER), "GROW, PUSH");
  46. frame.setTitle("US Map");
  47. frame.setSize(1500,900);
  48. frame.setLocationRelativeTo(null);
  49. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50. frame.setVisible(true);
  51. }
  52.  
  53. private void ApplyColor(String zip, Color color)
  54. {
  55. int x;
  56. int y;
  57. if(zip.equals("010"))
  58. {
  59. try
  60. {
  61. x = 3339;
  62. y = 672;
  63. FloodFill(x, y, new Color(mapImg.getRGB(x, y)), color);
  64. x = 3361;
  65. y = 681;
  66. FloodFill(x, y, new Color(mapImg.getRGB(x, y)), color);
  67. }
  68. catch(AWTException e)
  69. {
  70. e.printStackTrace();
  71. }
  72. }
  73. }
  74.  
  75. public void FloodFill(int x, int y, Color targetColor, Color replacementColor) throws AWTException
  76. {
  77. if(new Color(mapImg.getRGB(x, y)).equals(replacementColor))
  78. {
  79. return;
  80. }
  81.  
  82. g.setColor(replacementColor);
  83. g.fillRect(x, y, 1, 1);
  84.  
  85. if(new Color(mapImg.getRGB(x-1, y)).equals(targetColor))
  86. {
  87. FloodFill(x-1, y, targetColor, replacementColor);
  88. }
  89.  
  90. if(new Color(mapImg.getRGB(x+1, y)).equals(targetColor))
  91. {
  92. FloodFill(x+1, y, targetColor, replacementColor);
  93. }
  94.  
  95. if(new Color(mapImg.getRGB(x, y-1)).equals(targetColor))
  96. {
  97. FloodFill(x, y-1, targetColor, replacementColor);
  98. }
  99.  
  100. if(new Color(mapImg.getRGB(x, y+1)).equals(targetColor))
  101. {
  102. FloodFill(x, y+1, targetColor, replacementColor);
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement