473,321 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Calling a draw method from another class

Here is my draw method from my
Expand|Select|Wrap|Line Numbers
  1. Crayon class:
  2.  
  3. public void draw (Graphics screen, int x, int y) {
  4.    screen.setColor(crayonColor);
  5.    int xcoords [] = {x+50,x+25,x+150,x+150,x+50};
  6.    int ycoords [] = {y+50,y+0,y+50,y+550,y+550};
  7.    screen.fillPolygon(xcoords,ycoords,5);
  8. }
  9.  
  10. The applet I'm making is supposed to draw 8 crayons with a random color and different heights. Here is my code so far:
  11. import java.awt.*;
  12. import javax.swing.*;
  13. import java.util.*;
  14.    public class TestCrayon extends JApplet{
  15.       public void paint (Graphics page){
  16.       //random color
  17.       int r = (int)(Math.random()*(255-0+1)+1);
  18.       int g = (int)(Math.random()*(255-0+1)+1);
  19.       int b = (int)(Math.random()*(255-0+1)+1);
  20.       Color col = new Color(r, g, b);
  21.       //create crayon object
  22.       Crayon one = new Crayon(col,200);
  23.       one.draw();
  24.  
  25.       }
  26.       }
But I cannot figure out how to call the draw method. Thank you for the help in advance.
Sep 30 '14 #1
1 4112
chaarmann
785 Expert 512MB
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>)".
Oct 1 '14 #2

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

Similar topics

2
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() {
11
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...
6
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);
5
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...
1
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...
2
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...
6
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...
3
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...
0
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" ...
0
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:...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
0
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...
0
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...
1
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...
1
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....
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.