The Artima Developer Community
Sponsored Link

Java Answers Forum
How do you draw a rectangle with dotted or hashed lines?

1 reply on 1 page. Most recent reply: May 20, 2002 3:26 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
james smith

Posts: 8
Nickname: jochem
Registered: Apr, 2002

How do you draw a rectangle with dotted or hashed lines? Posted: May 16, 2002 5:13 AM
Reply to this message Reply
Advertisement
How do you draw a rectangle with dotted or hashed lines? Hope someone can help.


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
Reply to this message Reply
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

Flat View: This topic has 1 reply on 1 page
Topic: Why doesn't this work? Previous Topic   Next Topic Topic: How to get thing from set

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use