Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |
LaughAdactyl
|
Posted - 2008.01.28 04:55:00 -
[1]
Edited by: LaughAdactyl on 28/01/2008 04:56:34 ok heres the program, its long tho
// to draw random lines. import java.awt.Color; import java.awt.Graphics; import java.util.Random; import javax.swing.JPanel;
public class DrawPanel extends JPanel { private Random randomNumbers = new Random(); private MyLine lines[]; // array on lines private MyRectangle rectangles[]; //array on rectangles
// constructor, creates a panel with random shapes public DrawPanel() { setBackground( Color.WHITE );
lines = new MyLine[ 5 + randomNumbers.nextInt( 5 ) ]; rectangles = new MyRectangle[5 + randomNumbers.nextInt( 5) ];
// create lines for ( int count = 0; count < lines.length; count++ ) { // generate random coordinates int x1 = randomNumbers.nextInt( 300 ); int y1 = randomNumbers.nextInt( 300 ); int x2 = randomNumbers.nextInt( 300 ); int y2 = randomNumbers.nextInt( 300 ); //int height = randomNumbers.nextInt( 300 ); //int width = randomNumbers.nextInt( 300 );
// generate a random color Color lcolor = new Color( randomNumbers.nextInt( 256 ), randomNumbers.nextInt( 256 ), randomNumbers.nextInt( 256 ) );
// add the line to the list of lines to be displayed lines[ count ] = new MyLine( x1, y1, x2, y2, lcolor ); //rectangles[ count ] = new MyRectangle( x1, y1, x2, y2, rcolor); } // end for
for (int count = 0; count < rectangles.length; count++) { int x3 = randomNumbers.nextInt( 300 ); int y3 = randomNumbers.nextInt( 300 ); int x4 = randomNumbers.nextInt( 300 ); int y4 = randomNumbers.nextInt( 300 );
Color rcolor = new Color( randomNumbers.nextInt( 256 ), randomNumbers.nextInt( 256 ), randomNumbers.nextInt( 256 ) );
rectangles[ count ] = new MyRectangle( x3, y3, x4, y4, rcolor); } } // end DrawPanel constructor public void paintComponent( Graphics g ) { super.paintComponent( g );
// draw the lines for ( MyLine line : lines ) line.draw( g );
//draw the rectangles for( MyRectangle rectangle : rectangles) rectangle.draw( g ); } // end method paintComponent
} // end class DrawPanel
my rectangle.draw( g ); doesnt work, and i cannot figure out why, the for loop works as does the passing of the array, i just cannot get the rectangles to draw
|
pwnedgato
|
Posted - 2008.01.28 05:00:00 -
[2]
java makes my pc cry...
Originally by: Crumplecorn These is a forum for this.
|
Taedrin
Gallente Royal Hiigaran Navy
|
Posted - 2008.01.28 05:16:00 -
[3]
COpying the source into netbeans real quick, will get back to you after I finish debugging your code.
|
Yamalok
|
Posted - 2008.01.28 05:20:00 -
[4]
Edited by: Yamalok on 28/01/2008 05:20:19 OK, code copied and got my purdy code highlighting going.
First of all, I can't run the code cause I don't have your other classes (MyLine, MyRectangle), so I can only guess.
If the draw method is abstract, did you implement it properly?
/edit: Darn alt, Taedrin is my main.
|
ry ry
StateCorp The State
|
Posted - 2008.01.28 07:30:00 -
[5]
Originally by: pwnedgato java makes my pc cry...
the beauty of java is that it can make any platform running rhe JRE cry. [IMAGE REMOVED] |
Taedrin
Gallente Royal Hiigaran Navy
|
Posted - 2008.01.28 12:58:00 -
[6]
Originally by: ry ry
Originally by: pwnedgato java makes my pc cry...
the beauty of java is that it can make any platform running rhe JRE cry.
In C, you shoot yourself in the foot.
In Java, You locate the Gun class, but discover that the Bullet class is abstract, so you extend it and write the missing part of the implementation. Then you implement the ShootAble interface for your foot, and recompile the Foot class. The interface lets the bullet call the doDamage method on the Foot, so the Foot can damage itself in the most effective way. Now you run the program, and call the doShoot method on the instance of the Gun class. First the Gun creates an instance of Bullet, which calls the doFire method on the Gun. The Gun calls the hit(Bullet) method on the Foot, and the instance of Bullet is passed to the Foot. But this causes an IllegalHitByBullet exception to be thrown, and you die.
Shamelessly plaguerized from here.
|
Tarminic
Forsaken Resistance The Last Stand
|
Posted - 2008.01.28 15:27:00 -
[7]
It's been awhile since I've worked in Java, and even longer since I had to do any drawing with it, but I believe that any drawing actions have to be done by implementing the abstract paint method. ---------------- Tarminic - 31 Million SP in Forum Warfare Play EVE: Downtime Madness v0.78.2 |
Sharupak
Minmatar Knights Of the Black Sun Brotherhood Of Steel
|
Posted - 2008.01.28 16:12:00 -
[8]
php kthanks _______________________________________________ RuntimeError: ChainEvent is blocking by design, but you're block trapped. You have'll have to find some alternative means to do Your Thing, dude. |
LaughAdactyl
|
Posted - 2008.01.28 20:05:00 -
[9]
yeah i found the problem, i forgot to call the get methods, so everything was being set to null, now i gotta do polymorphism with MyShapes :(
|
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |