用java编写一个画图软件
1个回答
展开全部
package s;//包名
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
int x1,y1,x2,y2;public Test(){
setVisible(true);
setSize(300,300) ;
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0) ; }});
addMouseListener(
new MouseAdapter() {
public void mousePressed(MouseEvent e){
x1=e.getX();
y1=e.getY();} });
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e){
x2=e.getX() ;
y2=e.getY() ;
repaint(); }});
}
public void paint(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
x1=x2;
y1=y2;
}
public static void main(String args[])
{
new Test();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询