Re: paint program using canvas
Andy Cho wrote:
Hello all
I'm developing small paint program using canvas class.
But I don't know how retain lines which I draw.
All lines are disapeared when another window is on top of my paint
window.
And how can I control the thickness of lines.
Plaease give me an idea.
Thanks
Andy
import java.awt.*;
import java.awt.event.*;
public class test extends Canvas {
public test() {
setPreferredSize(new Dimension(640,480));
}
public void paint(Graphics g2d) {
Graphics2D g = (Graphics2D)g2d;
g.setColor(Color.GREEN);
g.drawLine(10,getHeight()/2,getWidth()-10,getHeight()/2);
g.setColor(Color.RED);
g.setStroke(new BasicStroke(6.0f));
g.drawLine(10,10,getWidth()-10,getHeight()-10);
g.setColor(Color.BLUE);
g.setStroke(new BasicStroke(2.0f));
g.drawLine(getWidth()-10,10,10,getHeight()-10);
}
public static void main(String[] args) {
final Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
f.dispose();
}
});
test t = new test();
f.add(t,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access