import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;
class MyPanel extends JPanel{
private int x1,y1,x2,y2;
public MyPanel()
{
addMouseListener(
new MouseAdapter()
{
public void mousePressed( MouseEvent event )
{
x1=event.getX();
y1=event.getY();
}
public void mouseReleased( MouseEvent event )
{
x2=event.getX();
y2=event.getY();
repaint();
}
}
);
addMouseMotionListener(
new MouseMotionAdapter()
{
public void mouseDragged( MouseEvent event )
{
x2=event.getX();
y2=event.getY();
repaint();
}
}
);
}
public Dimension getPreferredSize()
{
return new Dimension( 800,600 );
}
public void paintComponent( Graphics g )
{
super.paintComponent( g );
Graphics2D g2d = (Graphics2D )g;
g2d.draw( new Arc2D.Double(Math.min(x1,x2),Math.min(y1,y2),
Math.abs(x1-x2),Math.abs(y1-y2),0,270,Arc2D.PIE));
}
}
public class TestMyPanel extends JFrame{
private MyPanel myPanel;
public TestMyPanel()
{
myPanel = new MyPanel();
myPanel.setBackground( Color.YELLOW );
Container container= getContentPane();
container.setLayout( new FlowLayout() );
container.add( myPanel );
setSize( 800,600 );
setVisible( true );
}
public static void main( String args[] )
{
TestMyPanel test= new TestMyPanel();
test.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}