daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top