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

