Results 1 to 10 of 10
Thread: resizing a rectangle?
- 12-11-2010, 07:49 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
resizing a rectangle?
public void drawFrame()
{
myCanvas.getSize();
myCanvas.setForegroundColor(Color.black);
Rectangle rect = (new Rectangle(20,20,WIDTH - 20, HEIGHT - 20));
myCanvas.draw(rect);
}
Im trying to get the rectangle to change with the size of the canvas, when the canvas's size is changed, and leaving a 20px edge. However its only producing two line not a full rectangle? Any help be much appreciated.
-
Is this Swing? You may wish to create and post an SSCCE, and give us more details on your problem for quicker, better help. Please see the link for more info.
- 12-11-2010, 08:03 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
No im using blueJ and have imported the java.awt if that helps :)
- 12-11-2010, 08:19 PM #4
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
import java.awt.Color;
import java.awt.Rectangle;
import java.awt. Font;
/**
* Class BallDemo - provides a demonstration of the
* BouncingBall and Canvas classes.
*
*/
public class BallDemo
{
private Canvas myCanvas;
private static final int WIDTH = 600;
private static final int HEIGHT = 500;
/**
* Create a BallDemo object.
* Creates a fresh canvas and makes it visible.
*/
public BallDemo()
{
myCanvas = new Canvas("Ball Demo", WIDTH, HEIGHT);
myCanvas.setVisible(true);
}
/**
* Simulate two bouncing balls
*/
public void bounce()
{
int ground = 400; // position of the ground line
int xStart = 50; // x-start of the ground line
int xLimit = 550; // x-limit of the ground line
myCanvas.setVisible(true);
// draw the ground
myCanvas.setForegroundColor(Color.blue);
myCanvas.drawLine(xStart, ground, xLimit, ground);
// crate and show the balls
BouncingBall ball = new BouncingBall(xStart, 50, 16, Color.blue, ground, myCanvas);
ball.draw();
BouncingBall ball2 = new BouncingBall(xStart + 20, 80, 20, Color.red, ground, myCanvas);
ball2.draw();
// Make them bounce until both have gone beyond the xLimit.
boolean finished = false;
while(!finished) {
myCanvas.wait(50); // small delay
ball.move();
ball2.move();
// stop once ball has travelled a certain distance on x axis
if(ball.getXPosition() >= xLimit && ball2.getXPosition() >= xLimit) {
finished = true;
}
}
ball.erase();
ball2.erase();
}
/**
* Draw frame method...!
*/
public void drawFrame()
{
myCanvas.getSize();
myCanvas.setForegroundColor(Color.black);
Rectangle rect = (new Rectangle(20,20,this.WIDTH - 20, this.HEIGHT - 20));
myCanvas.draw(rect);
}
}
-
bluej is just the development environment you are using and has nothing to do with your current Java problem.
OK, so you're using the AWT library which is important.and have imported the java.awt if that helps :)
Still without more information and an SSCCE, about all I can do is wish you well.
Edit:
I see that you've posted code :)
... but without code tags, so it's hard to read. :(
Let me look at it...
Edit 2:
And the code isn't an SSCCE (you didn't read the link I posted in my first reply, did you?), and so I can't compile, run or test the code. :(
Anyway, best of luck.Last edited by Fubarable; 12-11-2010 at 08:24 PM.
-
Posted in private message:
Tell you what. Instead either create a JAR file with source code and convert the extension from jar to zip and post it here, or else simply place all the source files into a zip file and post it here in the forum (it allows text and zip file uploads). Also, most of us prefer all communication to be made through the forum, not through private messaging.
Originally Posted by ludis
- 12-11-2010, 10:09 PM #7
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
Ok here you go i think i know whats happening now just, cant solve it. I believe the Dimension object need int values and my accessor method is return values of type double.
-
Do you have a main class that has a main method? Either that or one that displays an applet?
- 12-11-2010, 10:28 PM #9
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
I just run the package.blueJ and it all comes up! In BlueJ of course....!
- 12-12-2010, 01:00 PM #10
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
does rectangle contain or overlap another rectangle?
By Xycose in forum New To JavaReplies: 6Last Post: 11-30-2010, 11:29 PM -
Wrong with Rectangle res = new Rectangle(0,0,0,0);???
By jiapei100 in forum AWT / SwingReplies: 3Last Post: 09-25-2010, 03:39 PM -
button not resizing in awt
By alinaqvi90 in forum AWT / SwingReplies: 1Last Post: 08-17-2010, 03:43 PM -
panel resizing
By simo_mon in forum AWT / SwingReplies: 1Last Post: 08-15-2009, 02:09 PM -
Image Resizing and DPi
By Rob_ in forum Java AppletsReplies: 4Last Post: 11-27-2008, 02:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks