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();
}
public void paint(Graphics g)
{
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();
}
}
以上是一个小程序,通过了编译,要实现的是当按下鼠标然后拖动,最后释放鼠标,会在起点和终点画一条直线,双击界面上的button键,则会关闭窗口。这个程序改了好几次,可还是画不出图,有哪个高手可以帮忙解答一下,万分感谢