position shapes / graphics

Hey,

Thanks for your help so far.

I found an example and edited it, it displays a circle, square and line all one after another. Ill post code to show ye;

package shape;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.BasicStroke;

import java.awt.Rectangle;

import java.awt.Graphics2D;

import java.awt.geom.Ellipse2D;

import java.awt.geom.Rectangle2D;

import java.awt.geom.Arc2D;

import java.awt.geom.Line2D;

import javax.swing.JPanel;

publicclass ShapesJPanelextends JPanel

{

// draw shapes with Java 2D API

publicvoid paintComponent( Graphics g )

{

super.paintComponent( g );// call superclass's paintComponent

Graphics2D g2d = ( Graphics2D ) g;// cast g to Graphics2D

// draw 2D ellipse filled with a blue-yellow gradient

g2d.setPaint( Color.BLACK);

g2d.fill(new Ellipse2D.Double( 5, 30, 65, 100 ) );

// draw 2D rectangle in red

g2d.setPaint( Color.BLACK );

g2d.setStroke(new BasicStroke( 2.0f ) );

g2d.draw(new Rectangle2D.Double( 80, 30, 65, 100 ) );

// draw 2D lines in green and yellow

g2d.setPaint( Color.BLACK );

g2d.draw(new Line2D.Double( 395, 30, 320, 150 ) );

}// end method paintComponent

}// end class ShapesJPanel

and also main to run the JPanel

package shape;

import javax.swing.JFrame;

publicclass Shapes2

{

// execute application

publicstaticvoid main( String args[] )

{

// create frame for ShapesJPanel

JFrame frame =new JFrame("Drawing 2D shapes" );

frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

// create ShapesJPanel

ShapesJPanel shapesJPanel =new ShapesJPanel();

frame.add( shapesJPanel );// add shapesJPanel to frame

frame.setSize( 425, 200 );// set frame size

frame.setVisible(true );// display frame

}// end main } // end class Shapes

}

So thats all good, but the thing is i cant seem to apply any BorderLayout to the shapes, i want to display them one after another on new lines.

eg Circle

Square

line

In that kind of order, opposed to left to right. Can someone tell me how this can be done thanks.

Mark

[4026 byte] By [mark16a] at [2007-10-3 1:44:07]
# 1
> i want to display them one after another on new lines.? Read the API. Change the location where you do the drawing of each shape.
camickra at 2007-7-14 18:42:16 > top of Java-index,Desktop,Core GUI APIs...
# 2
sorry thats what i mean, i dont understand how to use BorderLayoutManager with these graphics, and the above example does not seem to specify the pixel location of where to draw the shapes?Do ya mean the AWT library api?
mark16a at 2007-7-14 18:42:16 > top of Java-index,Desktop,Core GUI APIs...
# 3

> and the above example does not seem to specify the pixel location of where to draw the shapes?

What do you think all those numbers are for?

> Do ya mean the AWT library api?

I mean read the API for the methods you are using to draw the images. Found out the meaning of all the numbers you are using.

camickra at 2007-7-14 18:42:16 > top of Java-index,Desktop,Core GUI APIs...
# 4
The numbers just specify g2d.fill( new Ellipse2D.Double( 5, 30, 65, 100 ) ); I thought that was all to construct the circle, sorry; i now see the first 2 digits specify the exact positioning of the shape.
mark16a at 2007-7-14 18:42:16 > top of Java-index,Desktop,Core GUI APIs...
# 5

Hey guys

Another little prob, in my class i have all my shapes created and postioned as best i can, but now in my main method i try and add a label and pass a variable result into it but i either cant display it or absolute position it.

Apparently with absolute positioning i must set the frame layout to null first then postion the labels but setting the frame to null ends up not displaying my graphics.

Any other way to absolute position the label and stuff and still keep the graphics displaying.

BorderLayout manager works but is not accurate enough.

Mark

mark16a at 2007-7-14 18:42:16 > top of Java-index,Desktop,Core GUI APIs...