Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class MyFrame extends JFrame {
  2. public MyFrame() {
  3. MyPanel np = new MyPanel();
  4. Container cont = getContentPane();
  5. cont.add(np);
  6. setBounds(10, 10, 1000, 1000);
  7. setVisible(true);
  8. }
  9. }
  10.  
  11. class MyPanel extends JPanel {
  12.  
  13. int[][] country;
  14.  
  15.  
  16. public MyPanel() {
  17.  
  18. country = new int[10][2];
  19.  
  20. for (int city = 0; city < 10; city += 1) {
  21. country[city][0] = (int)Math.round(Math.random() * 900.0);
  22. country[city][1] = (int)Math.round(Math.random() * 900.0);
  23. }
  24.  
  25. }
  26.  
  27. public void paintComponent(Graphics gr) {
  28. gr.clearRect(0, 0, 1000, 1000);
  29. for (int city = 0; city < 10; city += 1) {
  30. gr.fillRect(country[city][0], country[city][1], 5, 5);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement