Problem with setStroke

Hi,

I am facing a problem regarding Stroke method.

I am drawing a dotted square on a frame using BasicStroke, it is working fine but when I try to draw a simple square on same frame , it is drawing dotted square only.

I have different class for Dotted Square and Plain Square.

Kindly tell me what I am doing wrong...

Here is the sample code.

For Dotted Square

public void drawFrame(Graphics g1) {

Rectangle r = displayBox();

Graphics2D g2d1=(Graphics2D)g1;

g2d1.setStroke (new BasicStroke(1f, BasicStroke.CAP_BUTT,

BasicStroke.JOIN_ROUND, 1f, new float[] {2f},0f));

g1.drawRect(r.x, r.y, r.width-1, r.width-1);

if(DrawingTool.bs!=null)

g2d1.setStroke(DrawingTool.bs);

}

For Plain Square

public void drawFrame(Graphics g) {

Rectangle r = displayBox();

g.drawRect(r.x, r.y, r.width-1, r.width-1);

//DrawingTool.bs=(BasicStroke)((Graphics2D)g).getStroke();

}

Looking forward for your co-operation.

Thanks

[1048 byte] By [rapida] at [2007-10-3 3:55:53]
# 1

import java.awt.*;

import javax.swing.*;

public class StrokeTest extends JPanel {

protected void paintComponent(Graphics g) {

super.paintComponent(g);

Graphics2D g2 = (Graphics2D)g;

Stroke origStroke = g2.getStroke();

System.out.println("origStroke = " + origStroke);

g2.setStroke (new BasicStroke(1f, BasicStroke.CAP_BUTT,

BasicStroke.JOIN_ROUND,

1f, new float[] {2f},0f));

g2.drawRect(40, 40, 100, 100);

g2.setStroke(origStroke);

g2.drawRect(40, 200, 100, 100);

}

public static void main(String[] args) {

JFrame f = new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.getContentPane().add(new StrokeTest());

f.setSize(400,400);

f.setVisible(true);

}

}

74philipa at 2007-7-14 21:54:02 > top of Java-index,Security,Cryptography...
# 2
Thanks!
rapida at 2007-7-14 21:54:02 > top of Java-index,Security,Cryptography...