您的位置:首页 > 电脑网络 > 电脑配件 > javaGUI界面3-DrawLine

javaGUI界面3-DrawLine

luyued 发布于 2011-02-05 08:42   浏览 N 次  

****************************************************************

package myprojects.drawline;

import java.awt.Graphics;

public class MyLine {
private int orgX;
private int orgY;
private int endX;
private int endY;

public MyLine(int orgX,int orgY,int endX,int endY)
{
this.orgX = orgX;
this.orgY = orgY;
this.endX = endX;
this.endY = endY;
}
public void drawMe(Graphics g)
{
g.drawLine(orgX,orgY,endX,endY);
}
}

**********************************************************

package myprojects.drawline;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

class DrawLine extends Frame {

int orgX;
int orgY;
int endX;
int endY;

Vector vLines = new Vector();
public void paint(Graphics g)
{
Enumeration e= vLines.elements();
while(e.hasMoreElements())
{
MyLine line = (MyLine)e.nextElement();
line.drawMe(g);
}
}
public DrawLine()
{
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
orgX = e.getX();
orgY = e.getY();
}
public void mouseReleased(MouseEvent e)
{
endX = e.getX();
endY = e.getY();

vLines.add(new MyLine(orgX,orgY,endX,endY));
repaint();
}

}

);
}
public static void main(String[] args) {
// TODO: Add your code here
System.out.println("Starting DrawLine..");
DrawLine mainFrame = new DrawLine();
mainFrame.setSize(400,400);
mainFrame.setTitle("DrawLine");
mainFrame.setVisible(true);
}
}


MSN空间完美搬家到新浪博客!

上一篇:V-LINE四方脸整形 下一篇:够劲的生日
图文资讯
广告赞助商