the following code draw simply two lines..
the problem , there is a bug that i could not find it ..
if i run the prograe some times i tdraw the lines ... ans some times not .. i dont know why ..
if you have any idea about the bug .. can you inform me
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.*;
public class DrawShapes extends JFrame {
private Color color = Color.black;
private Graphics g;
private Graphics2D g2D;
private int LineWidth;
public DrawShapes()
{
super("test Paint Class");
setSize(400,400);
setVisible(true);
}
//set&get the color---------------------------------------------------------------
public void setColor2(Color newColor)
{ color = newColor; }//end method setColor
public Color getColor()
{return color;}// end method getColor
// method to set the values of Graphics, Color, ------------------------------
public void setG()
{
//g = super.getGraphics();
g = getContentPane().getGraphics();
g.setColor(color);
g2D = (Graphics2D) g;
}// end method setG
// to draw a line-------------------------------------------------------------
public void drawLine2(Point Start , Point End)
{
setG();
g2D.drawLine(Start.x , Start.y , End.x , End.y);
}//end method
public static void main(String[] args) {
DrawShapes d = new DrawShapes();
Point p1 = new Point(30,50);
Point p2 = new Point(150,260);
d.drawLine2(p1,p2);
d.setColor2(Color.white);
p1.setLocation(150,260);
p2.setLocation(150,10);
d.drawLine2(p1,p2);
System.out.println();
}//end the main method
}// end class DrawShapes