• 周三. 9月 27th, 2023

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Calling a draw method from another class – Java From 5gw.org

[db:作者]

4月 9, 2022

xmlns=”http://www.w3.org/1999/xhtml” dir=”ltr” lang=”en”>
Calling a draw method from another class – Java
/**
* Bytes CSS
* Style: ‘bytes.answers’; Style ID: 18
*/
@import url(“/clientscript/vbulletin_css/style-12635a82-00018.css”);

 
 
470,370 Members | 1,542 Online

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 3434


(adsbygoogle = window.adsbygoogle || []).push({});

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


Message
 
Cancel Changes

Post your reply

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

Similar topics


2 posts

views

Thread by kingofkolt |
last post: by


6 posts

views

Thread by Rob Cowie |
last post: by


reply

views

Thread by perto1 |
last post: by


reply

views

Thread by cosinus |
last post: by

By using this site, you agree to our Privacy Policy and Terms of Use.


(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-90111-7’, ‘bytes.com’);
ga(‘send’, ‘pageview’);

loadBytesTracking()

//0){location.replace(‘https://bytes.com/showthread.php?p=’+cpostno);};} }

if(typeof window.orig_onload == “function”) window.orig_onload();
}

//]]>

《Calling a draw method from another class – Java From 5gw.org》有5个想法

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注