How can you draw using Swing components?

Answer Posted / chandra rekha

use the getGraphics method to get an object of the graphics
class and with that object we can perform draw methods.
for example
public class myclass extends...implements ActionListener
{
...
...
....
public void actionPerformed(ActionEvent ae)
{
if(ae==....)
{
Graphics g=getGraphics();
g.drawLine(100,200,150,250);
}
}
.....

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is layout in java swing?

619


Why are swings considered lightweight?

642


What are swing components?

685


What is the process of setting the layout manager?

661


What is the use of java swing?

628






What are the components of swing in java?

633


Which is better swing or awt?

616


Why would you use swingutilities.invokeandwait or swingutilities.invokelater?

636


What is the difference between swing and awt in java?

625


Why should any swing call back implementation execute quickly?

697


How to add calendar in java swing using eclipse?

857


Why swing is used in java?

629


What is the use of double buffering in swings?

651


Which method is used for setting security in applets?

678


What is an event handler in swing?

714