62,621
社区成员
发帖
与我相关
我的任务
分享
//不知道为什么会带一堆稀奇古怪的东西,请点右边的那个小图标进行复制
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class A {
public static void main(String[] args) {
new MyFrame();
}
}
class MyFrame extends Frame {
private int lineaX = 100, lineaY = 100;
private int linebX = 100, linebY = 300;
public MyFrame() {
this.setBounds(100, 100, 400, 400);
this.setLayout(null);
this.setVisible(true);
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
switch(e.getButton())
{
case MouseEvent.BUTTON1:
lineaX += 5;
linebX += 5;
break;
case MouseEvent.BUTTON3:
lineaX -= 5;
linebX -= 5;
break;
}
repaint();
}
});
}
public void paint(Graphics g) {
g.drawLine(lineaX, lineaY, linebX, linebY);
}
}