Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import javax.swing.JComponent;
- import javax.swing.JFrame;
- public class Clouds
- {
- public static void main(String[] args)
- {
- JFrame frame = new JFrame();
- frame.setSize(500,500);
- frame.setVisible(true);
- //frame.setBackground(Color.blue);
- Cloud myCloud = new Cloud(300, 300);//component
- frame.getContentPane().add(myCloud);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- } //class cloud ends here (that is one class)
- class Cloud extends JComponent
- {
- private int posX, posY;
- public Cloud(int x, int y){
- this.posX = x;
- this.posY = y;
- }
- public void paint(Graphics g)
- {
- Graphics2D g2d = (Graphics2D)g; //remember that casting is here
- int w = getWidth();
- int h = getHeight();
- g2d.setColor(Color.blue);
- g2d.fillRect(0, 0, w, h);
- g.setColor(Color.white);
- g.fillOval(posX, posY, 110, 50);
- for(int i = 0; i < 5; i++)
- {
- int x = (int)(Math.random() * 110 + posX);
- int y = (int)(Math.random() * 50 + posY);
- g.fillOval(x, y, 110, 50);
- }
- /*
- g.setColor(Color.white);
- g.fillOval(300, 300, 75, 50);
- for(int i = 0; i < 20; i++)
- {
- int x = (int)(Math.random()*350);
- int y = (int)(Math.random()*325);
- g.setColor(Color.white);
- g.fillOval(x, y, 75, 50);
- }
- */
- g2d.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement