import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class listener extends MouseAdapter
{
private int x1,y1,x2,y2;
public void mousePressed(MouseEvent evt)
{
x1=evt.getX();
y1=evt.getY();
}
public void Released(MouseEvent evt)
{
x2=evt.getX();
y2=evt.getY();
Graphics g=getGraphics();
g.drawLine(x1,y1,x2,y2);
}
}
class mypanel8 extends JPanel
{
private JButton bt;
public mypanel8()
{
bt=new JButton("exit");
add(bt);
bt.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent evt)
{
int i=evt.getClickCount();
if(i==2)
System.exit(0);
}
});
listener listener1=new listener();
addMouseListener(listener1);
}
}
class myframe8 extends JFrame
{
public myframe8()
{
mypanel8 pp8=new mypanel8();
Container pane=getContentPane();
pane.add(pp8);
setSize(300,300);
setLocation(300,100);
setTitle("test");
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
}
}
public class test
{
public static void main(String args[])
{
myframe8 fm8 =new myframe8();
fm8.show();
}
}
请大家看看这个程序要实现的是界面中有一个按键当双击时会关闭窗口,在面板上按下鼠标,拖动然后放开鼠标自动画出一条直线,getGraphics 总是错,究竟该怎么用