Here is my draw method from my - Crayon class:
-
-
public void draw (Graphics screen, int x, int y) {
-
screen.setColor(crayonColor);
-
int xcoords [] = {x+50,x+25,x+150,x+150,x+50};
-
int ycoords [] = {y+50,y+0,y+50,y+550,y+550};
-
screen.fillPolygon(xcoords,ycoords,5);
-
}
-
-
The applet I'm making is supposed to draw 8 crayons with a random color and different heights. Here is my code so far:
-
import java.awt.*;
-
import javax.swing.*;
-
import java.util.*;
-
public class TestCrayon extends JApplet{
-
public void paint (Graphics page){
-
//random color
-
int r = (int)(Math.random()*(255-0+1)+1);
-
int g = (int)(Math.random()*(255-0+1)+1);
-
int b = (int)(Math.random()*(255-0+1)+1);
-
Color col = new Color(r, g, b);
-
//create crayon object
-
Crayon one = new Crayon(col,200);
-
one.draw();
-
-
}
-
}
But I cannot figure out how to call the draw method. Thank you for the help in advance.
1 4112
You are calling "one.draw()", but do not pass any parameters the method needs. Passing poarameters means for example calling "one.draw(g, 100, 100);". Where g is an instance of Graphics class. If you do not have this instance, just create it with "Graphics g = new Graphics(<parameters>)".
Sign in to post your reply or Sign up for a free account.
Similar topics
by: kingofkolt |
last post by:
hi all,
just wondering what the syntax is for calling a method of a class from
another method of that same class?
for example...
class Test {
var $test="foo";
function printTest() {
|
by: Bob Rock |
last post by:
Hello,
I'd like to be able to allow instanciation of a class (class Class_A) only
from another class method (class Class_B). And I'd like to write the
necessary code to enforce this behavior...
|
by: John |
last post by:
I wrote this class
class CLine
{
public float sX,sY,dX,dY,m,x,y;
public void Draw (PaintEventArgs g)
{
//Graphics g = this.CreateGraphics
();
Bitmap bm=new Bitmap(1,1);
|
by: Mark |
last post by:
What I want to do is call a function in my main form/class from the
server (which the another program/client calls). The main form does
not really create a server object so I can't pass the...
|
by: JPSutor |
last post by:
I am trying to contola progress bar on a form from a method that is
located in annother class.
when I try and instantiate the form
Form1 frm = new Form1;
frm.ProgressBar1.PerformStep();
I get...
|
by: Macca |
last post by:
Hi,
I have a windows form project. The form class has a number of methods in it
that i want to call from another class I have just created.
This class is a finite state machine and is created...
|
by: Rob Cowie |
last post by:
Hi all,
Is there a simple way to call every method of an object from its
__init__()?
For example, given the following class, what would I replace the
comment line in __init__() with to result...
|
by: Jayman777 |
last post by:
Hello, I am using PHP 4.4.1 and am having problems retrieving an object
from an array of objects and then calling a method on it. Here are two
simple classes that I am using:
class Day...
|
by: vatcrack |
last post by:
Hi guys,
I'm kind of new to C++. I encountered following problem. I would like to create a class from where i can read data from files. So implemented
FILEREADER.CPP:
#include "filereader.h"
...
|
by: Rik Moed |
last post by:
Hi all,
I encounter a problem with a library method that should create a multi
dimensional string array.
Below is the method:...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |