Results 1 to 8 of 8
- 06-29-2011, 12:44 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
Drawing in Java? or Maybe movable buttons?
Hello, I wanted to create a program that could calculate how big amount of boxes can a room fit. Boxes are different size all the time and you never know what dimension you are going to get. I wanted to make it somewhat visual by lets say a user enters dimensions and a box is drawn. I also need to make sure that the box fits in the room and they are not drawn one over another.
My idea is to just simply create buttons that user can move so user can see for himself if they fit or not, also have a function that auto arranges boxes (This is extra for later)
Now I Need a way to do this and i never learned anything like this in school, I only finished 1 year of java programming and got few months till next so I am trying to do something new to keep up with my programming.
Is there a way to make buttons movable once created in a compiled program. Or is there a way for java to draw regular boxes in compiled program and delete them?
Thanks upfront for taking the time to help me out.
EDIT: The movable buttons needs to be dragged with a mouse and be leveled up with edges of the room or other boxes.Last edited by Bagzli; 06-29-2011 at 01:41 AM.
- 06-29-2011, 02:03 AM #2
Yes you can draw things at different locations and move them around.
Look at Mouse Listeners for how to detect where the mouse/cursor is located and where it is moving.
Look at overriding the paintComponent() method for redrawing a shape on a panel.
- 06-29-2011, 02:24 AM #3
Like Norm said, stick to drawing. Don't try to shift components like buttons or panels around: they have "a life of their own" (risizing, being influenced by layoutmanagers etc.).
If you use java.awt.geom.Rectangle2D or other Shapes and don't rotate your boxes, you have a built in collisiondetection for points and rectangles with contains() and intersects().Last edited by Jodokus; 06-29-2011 at 11:37 AM. Reason: spelling
No bug ever had to calculate its fitnessfunction.
- 06-29-2011, 04:16 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
- 06-29-2011, 04:20 AM #5
Jodokus comments were an answer to your concern. The Rectangle class has the methods he mentioned that will help you with your concernI also need to make sure that the box fits in the room and they are not drawn one over another.
- 06-29-2011, 04:28 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 63
- Rep Power
- 0
I'v never used Rectangle2D class before nor have i ever drawn something with Java, I was wondering if somebody can point me in the right direction with a guide maybe? I was googling for some example and it appears some guy is using Applets to draw, now I'm not sure if this is how you really are suppose to do it or is there a more efficient way?
- 06-29-2011, 05:27 AM #7
The code to draw shapes uses the Graphics class methods in the paintComponent() method. It has nothing to do with applets. Search on the forum for paintComponent or for fillRect or for drawLine for sample code that draws shapes.
- 06-29-2011, 11:57 AM #8
Norm explained most. If you want to know when your cursor is on a box, when boxes are colliding or when your boxes try to penetrate the wall, you need some form of collisiondetection. Shapes (including the mentioned rectangle) have some methods to do this for you.Would you please elaborate?
Just try to practice some basic drawing, then add moving by the cursor (not the same as just following the cursor as in the next tutorial), then try to make your boxes and wall inpenetrable.
The basic paintingtutorial Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing) shifts a box around, but doesn't use Shapes. (I now risk banning for telling too much.)Last edited by Jodokus; 06-29-2011 at 12:19 PM. Reason: functions to methods
No bug ever had to calculate its fitnessfunction.
Similar Threads
-
Drawing labels/buttons on an image
By Eric Coulthard in forum Java 2DReplies: 0Last Post: 05-25-2010, 10:11 PM -
Java SWT Transparent Buttons
By ynnorj in forum AWT / SwingReplies: 7Last Post: 11-25-2009, 05:48 AM -
JToolBar movable but not floatable
By Fosters in forum AWT / SwingReplies: 0Last Post: 08-22-2008, 03:04 PM -
movable image with buttons
By boytjie in forum NetBeansReplies: 0Last Post: 04-18-2008, 12:00 PM -
How can i set the table's column dragable/movable false and cell editable
By johnt in forum AWT / SwingReplies: 4Last Post: 05-19-2007, 11:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks