Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: How do you draw a rectangle with dotted or hashed lines?
|
Posted: May 20, 2002 3:26 PM
|
|
This code is inspired from many places. I will put the main references ASAP.
package test.gui.test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.BasicStroke;
import java.awt.Stroke;
import java.awt.geom.*;
import org.apache.log4j.*;
/**
* The purpose of this class is to :
* Show how to draw dotted-line
*
* Code is copyleft.
* @author <a href="mailto:tsmets@altern.org">Thomas SMETS, Brussels</a>
* @version 0.0.2 initial
*/
public class DottedRectangle
{
JFrame jf = new JFrame ("DottedRectangle");
Category log = Category.getInstance (DottedRectangle.class);
Graphics g;
DottedRectangle ()
{
jf.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
jf.setSize ( 400, 400);
jf.setVisible (true);
g = jf.getContentPane ().getGraphics ();
Graphics2D g2d = (Graphics2D) g;
g.setColor (Color.red);
g2d.setBackground (Color.blue);
g2d.setStroke (
new BasicStroke(
1f,
BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND,
1f,
new float[] {2f},
0f) );
g.drawRect (100,100,100,100);
}
/**
*
*/
public static void main (String[] args)
{
BasicConfigurator.resetConfiguration ();
BasicConfigurator.configure ();
DottedRectangle DR = new DottedRectangle ();
}
}
Thomas SMETS, SCJP2 - Brussels
|
|