i am very bigginer to java .i trying to draw a line in a jpanel (using netbean ide)..i read some articles .but problem is it draw thais line without calling it .i want to draw l
Problem: You have no event code in your button event handler.
Modify state variable on button click.
private void jButton1ActionPerformed(
java.awt.event.ActionEvent evt) {
Graphics gg = null;
// TODO add your handling code here:
showLine = (true) ? false : true;
}
Add condition checking to paint method.
@Override public void paint(Graphics g) { Graphics2D ga = (Graphics2D)g;
if (showLine) {
ga.setPaint(Color.red);
ga.drawLine(200,100,200,300);
}
}