By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 822 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

Applets :(

P: 45
hi all you guys out there!

Im trying to solve this que, and its kind of bothering me..........I hate applets:(

- Write a program to draw n number of randomly generated circles on the applet where n is accepted as a parameter.

i did this but i dnt know how i can "randomly" generate them

Expand|Select|Wrap|Line Numbers
  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.FlowLayout;
  4. import java.awt.Graphics;
  5.  
  6. public class circles extends Applet{
  7.     public void init(){
  8. //         setting the applet size
  9.         setSize(85,200);
  10.  
  11.         // setting the background color on applet panel
  12.         this.setBackground(Color.WHITE);
  13.  
  14.         // setting the layout on applet panel
  15.         setLayout(new FlowLayout());
  16.     } 
  17.  
  18.     public void paint(Graphics g){
  19.         g.drawOval(100,100,60,60);
  20.         //g.drawOval(100,100,60,60);
  21.     } 
  22. }
thanks and i hope that you guys can help me out!!

outofmymind
Nov 13 '06 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
hi all you guys out there!

Im trying to solve this que, and its kind of bothering me..........I hate applets:(

- Write a program to draw n number of randomly generated circles on the applet where n is accepted as a parameter.

i did this but i dnt know how i can "randomly" generate them

Expand|Select|Wrap|Line Numbers
  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.FlowLayout;
  4. import java.awt.Graphics;
  5.  
  6. public class circles extends Applet{
  7.     public void init(){
  8. //         setting the applet size
  9.         setSize(85,200);
  10.  
  11.         // setting the background color on applet panel
  12.         this.setBackground(Color.WHITE);
  13.  
  14.         // setting the layout on applet panel
  15.         setLayout(new FlowLayout());
  16.     } 
  17.  
  18.     public void paint(Graphics g){
  19.         g.drawOval(100,100,60,60);
  20.         //g.drawOval(100,100,60,60);
  21.     } 
  22. }
thanks and i hope that you guys can help me out!!

outofmymind


Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.swing.*;
  3. import java.awt.Color;
  4. import java.awt.FlowLayout;
  5. import java.awt.Graphics;
  6. public class circles extends JApplet{
  7.  private int number;
  8.  public void init(){
  9. //   setting the applet size
  10.   setSize(500,500);
  11.   number = Integer.parseInt(JOptionPane.showInputDialog(this, "Enter number of circles"));
  12.   // setting the background color on applet panel
  13.   this.setBackground(Color.green);
  14.   // setting the layout on applet panel
  15.   //setLayout(new FlowLayout());
  16.  }
  17.  public void paint(Graphics g){
  18.   g.setColor(Color.blue);
  19.   for(int i = 0; i < number; i++) {
  20.    int diameter = 30 + (int)(Math.random()*50);
  21.    int xpos = diameter + (int)(Math.random()*(getWidth() - diameter));
  22.    int ypos = diameter + (int)(Math.random()*(getHeight() - diameter));
  23.    g.drawOval(xpos,ypos,diameter,diameter);
  24.   }
  25.   System.out.println(getWidth());
  26.   System.out.println(getHeight()); 
  27.  }
  28. }
  29.  
Like this?
Nov 13 '06 #2

P: 45
Thanks r035198x............your the best :D

outofmymind
Nov 14 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.