Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners random color fill

Have Programming Question? Ask it here!
 
 
 


Patrick Falzon
random color fill
0 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


Hi I am trying to create a randomly color filled oval but the outcome is a black filled oval this is the code: package assignment2;

import java.awt.Color; import java.awt.Graphics; import java.util.Random; import javax.swing.JPanel;

public class RandomDrawPanel extends JPanel {

@Override
protected void paintComponent(Graphics g) {

    int x = 5;
    int y = 7;
    Random rcolor = new Random();
    int r = rcolor.nextInt(255);
    int g1 = rcolor.nextInt(1);
    int b = rcolor.nextInt(250);

    g.drawOval(x, y, 200, 200);
    g.fillOval(x, y, 200, 200);
    Color randomColor = new Color(r, g1, b);

}

}

and for the output:

package assignment2;

import javax.swing.JFrame;

public class RandomDrawing {

/**
 * @param args
 */
public static void main(String[] args) {
    RandomDrawing shape = new RandomDrawing();
    shape.go();

}

private void go() {
    // TODO Auto-generated method stub
    JFrame frame = new JFrame();
    RandomDrawPanel oval = new RandomDrawPanel();
    frame.getContentPane().add(oval);
    /*try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println(e);
    }*/
    frame.setSize(500,500); 
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
random color fill
random color fill   Hi I am trying to create a randomly color filled...; Random rcolor = new Random(); int r = rcolor.nextInt(255); int g1...); g.fillOval(x, y, 200, 200); Color randomColor = new Color(r, g1, b
Generating Random Numbers to Fill array. Java Beginner needing help!
Generating Random Numbers to Fill array. Java Beginner needing help!  ... a program that produces random permutations of the numbers 1 to 10. eg... the permuted numbers. Make a second array and fill it with the numbers 1 to 10
Advertisements
Filling Color in Excel Using JSP
a sheet  and then  fill background color ,pattern and forground color...): This method is used to fill the for ground color of the style sheet. setFillPattern... is used to fill the background color. You can be used the following fields
Fill in the blanks.
Fill in the blanks.   Fill in the blanks. 1 ___operator is used to crate an array. 2 ___method can be called without the instance of a class. 3 When an interface method is implemented in a class. it must be declared
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
filling oval color in excel using jsp
a sheet  and then after we create a oval and fill color into oval.  Code... row setFillColor(Color color): This method is used to fill the color... filling oval color in excel using jsp   
random number
random number  Sir could u please send me the code registration form of roseindia.net with image varification
random number
random number   Please How do I generate a program that gives me random integer from 115 to 250? Using java.util.random. Thank you very much!  ...[] args){ int min = 115; int max = 250; Random random = new Random
Fill-in: Hammurabi I
Java NotesFill-in: Hammurabi I Name ______________________________ Fill in the blanks in these programs. Each blank represents ONE keyword, variable... yieldPerAcre = 2 + (int)(5 * _____________.random()); myHarvest
random numbers
random numbers  hi.. i am creating a website and on feedback form to authenticate user i want to generate a random number on label.if user types that number correctly in textbox then he is allowed to submit feedback otherwise
Pick at Random
the entry from the array before selecting another name at random
fill combobox at runtime jsp
fill combobox at runtime jsp  i have 1 combobox in jsp which is filled with value from sql db on load of form <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn
random numbers
random numbers  Hi I need some help with the code for the this program. This program should randomly choose a number between 1 and 1000, and then challenge the user to guess what it is, giving hints ('too high!' or 'too low
Random in jsp
Random in jsp          Random numbers are the numbers that are determined entirely by chance. User does not have any control over the working of random numbers
Color
to create new colors, and predefines a few color constants (see below.... White is (255, 255, 255) and black is (0,0,0). Color Constants Java originally defined a few color constant names in lowercase, which violated
How to fill double array in java
How to fill double array in java  how to fill double array in java
Random Access File.
Random Access File.  Explain Random Access File
Auto Fill Textbox - Java Beginners
Auto Fill Textbox   hi i am going to develope a php page with a select box and i want that this select box get auto fill when i write on it. please help me
using random number
using random number  generate a 10 digit number using random number and display the length of longest increasing series
Random Access File class
Random Access File class  Write a short note on Random Access File class.   Please visit the following link: Java Random Access File
getting random number in java
getting random number in java  getting random number in java Hi everyone, i am trying to get a random number in a particular range. for example random numbers between 1 to 100 in Java. Though i m new to Java, i have tried many
Generate Random Numbers
Generate Random Numbers  hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit
Random data - Java Beginners
Random data  hi friend, I want to ask how to make random data. i has example word like this : Gaza! Gaza! Palestina merdeka! how to make random like : Azag! Azag! Anitselap akedrem! thank's
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  In a random access file, first write the alphabets a,b, c, d till z. Read the file in reverse order and print it on screen
using random number
using random number  generate 10 number and display the length of longest incresing series
using random number
using random number  generate 10 digit number and display the length of longest incresing swries
Fill-in Questions: Hammurabi
Java Notes Fill-in Questions: Hammurabi Name ______________________________________ Fill in the underlined areas with ONE appropriate keyword, variable, operator, punctuation character etc, or leave it blank if you think
random numbers - Java Beginners
random numbers  write a program to accept 50 numbers and display 5... java.util.*; class RandomNumberExample { static Random generator = new Random...(); System.out.println("Random numbers are: "); int random[]=new int[5]; for(int i=0;i
Random numbers - Introduction
Java NotesRandom numbers - Introduction When to use random numbers There are many types of programs that use random numbers. Game programs use them... situation, or a deck of cards must be shuffled. Simulations usually use random
color change
color change  how to change the color in circle using scrollbar
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program that stores the names of four employees in an array of strings. Store the contents of the array in an alphabetical order in a file and display it back on console. Do not use
Random Creation of password
Random Creation of password  Dear Sir I have created a form with some details in it.When clicking on the submit button it gives me a password... to generate a random password and insert into database... Please help me out
Random numbers - Development process
Random numbers  hi, How to generate unique random numbers between range like(10 to 50)  Hi friend, class RandomNumber { public static void main(String[] args) { //set the variable aNumber
random numbers - Java Beginners
random numbers  Hello i need this code to be modified for me to display the random numbers, but not twice or more. I mean i need a number... RandomNumberExample { static Random generator = new Random(); public static int get (int[] array
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to use a File object and print even numbers from two to ten. Then using RandomAccessFile write numbers from 1 to 5. Then using seek () print only the last 3 digits
PHP GD Gradient Fill
++) { $background_color = ImageColorAllocate($image, $i, $i, $i); } $text_color = ImageColorAllocate($image, 255, 255, 255); $tekst = "Roseindia"; ImageString($image, 4, 30, 50, "$tekst", $text_color
Generating random numbers in a range with Java
Generating random numbers in a range with Java  Generating random numbers in a range with Java
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to write the details of an employee to a file. Details such as year of joining, department code, employee name and salary should be included. You must use RandomAccessFile
color cycle
color cycle  how do you implement a program for color cycle that has a button such that when i press the button it brings a sequence for example green-red-grey-green e.t.c and should use the getter methods and set methods
How to design a color in the bucket, design a color in the bucket, color in the bucket
How to design a color in the bucket       Fill color in the blank bucket by taking help.... Color: Choose "f30011" color and Ellipse tool (U key) to draw
J2ME Random Number
J2ME Random Number       In this application we are going to generate the random number using Random class. The Random class within the java.util package and we can use
textfield should not allow the user to fill the date in it.
textfield should not allow the user to fill the date in it.  I got.... Here user should not fill the date inside the text field manually. If he tries to fill the date manually, i have to display some message like "please click
Non-edit Combobox with auto fill - Swing AWT
JCombobox with auto fill capability. Auto fill is working only for the first character...". The requirement is to extend this auto fill capability to support multiple characters in non... characters typed by the user for auto fill for JCombobox in non-editable mode
Retrieving Data from Database to fill Combo Box
Retrieving Data from Database to fill Combo Box  Sir, I have a JSP Page with a combo box and a label. I have a database that has two fields id and an image. Now I want to fill the combo box with image and on selecting
fill out forms on web pages - JDBC
fill out forms on web pages    I want to fill out forms on web pages, it's is very important to my project. For example there is a web-site www.blauh...com , in which there wil be a form , what i hav to do is to fill that form
generate random numbers and display the largest
generate random numbers and display the largest  Hi, I am using... creates an array and fills it with random ints, prints the contents... ArrayRandom{ public static void main(String args[]){ Random r = new Random
understanding buttons :JSP random no program
understanding buttons :JSP random no program  I hav java random... random no between 100 and 200 on loading and on clicking submit button it ives... "no is greater" please help me to understand buttons .thank you java code for random
PHP Random Number
PHP Generate Random Numbers: A random number is becoming more useful.... To generate random number, PHP provides rand() function. ... Value A random value  Example : <
 

 

 

DMCA.com