Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyFrame extends JFrame {
- public MyFrame() {
- MyPanel np = new MyPanel();
- Container cont = getContentPane();
- cont.add(np);
- setBounds(10, 10, 1000, 1000);
- setVisible(true);
- }
- }
- class MyPanel extends JPanel {
- int[][] country;
- public MyPanel() {
- country = new int[10][2];
- for (int city = 0; city < 10; city += 1) {
- country[city][0] = (int)Math.round(Math.random() * 900.0);
- country[city][1] = (int)Math.round(Math.random() * 900.0);
- }
- }
- public void paintComponent(Graphics gr) {
- gr.clearRect(0, 0, 1000, 1000);
- for (int city = 0; city < 10; city += 1) {
- gr.fillRect(country[city][0], country[city][1], 5, 5);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement