addMouseMotionListener
importjava.awt.*;importjava.awt.event.*;publicclassapp18_10extendsFrame{intx1,x2,y1,y...
import java.awt.*;
import java.awt.event.*;
public class app18_10 extends Frame
{
int x1,x2,y1,y2;
Graphics g=getGraphics();
public app18_10()
{
a p=new a();
setTitle("Frame drawing");
setSize(200,150);
addMouseListener(p);
addMouseMotionListener(p);
setVisible(true);
}
public static void main(String af[])
{
app18_10 frn=new app18_10();
}
public void paint(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}
class a extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
}
public void mouseDragged(MouseEvent e)
{
x2=e.getX();
y2=e.getY();
paint(g);
x1=x2;
y1=y2;
}
}
} 展开
import java.awt.event.*;
public class app18_10 extends Frame
{
int x1,x2,y1,y2;
Graphics g=getGraphics();
public app18_10()
{
a p=new a();
setTitle("Frame drawing");
setSize(200,150);
addMouseListener(p);
addMouseMotionListener(p);
setVisible(true);
}
public static void main(String af[])
{
app18_10 frn=new app18_10();
}
public void paint(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
}
class a extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
}
public void mouseDragged(MouseEvent e)
{
x2=e.getX();
y2=e.getY();
paint(g);
x1=x2;
y1=y2;
}
}
} 展开
1个回答
名片
2024-10-28 广告
2024-10-28 广告
作为优菁科技(上海)有限公司的一员,Altair HyperWorks是我们重点代理的CAE软件套件。该软件以其全面的仿真能力、丰富的建模工具和高效的优化设计功能著称,广泛应用于汽车、航空航天、能源及电子等行业。HyperWorks通过集成...
点击进入详情页
本回答由名片提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询