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空间完美搬家到新浪博客!
- 05-20· 证 据 目 录的格式
- 05-14· 发现一个BUG nForce2 的主板
- 05-14· NEC EXPRESSCLUSTER X3.0 FOR WIN
- 05-14· 最近有什么好听的歌呢?
- 05-13· 小园子的惊喜
- 05-13· 推荐的电脑配置
- 05-13· 飒飒秋风起,点点胭脂泪
- 05-13· 振作!!
- 05-11· 宏碁/精英有意并购浩鑫
- 05-11· [转]真实:17岁少年在校不
- 05-09· 3、21--3、25成长足迹公布
- 05-09· 和小伙伴闹矛盾(3月5日)
- 05-09· 浩鑫简约 X27D
- 05-09· 今天有点烦躁
- 05-09· 为什么富士康郭台铭最看
- 05-09· 南通热线信息超市_南通汽
- 05-09· [置顶]iPad2零组件供应商剖
- 05-09· 北京富士康科技有限公司
- 05-09· 富士康去年亏损2.18亿美元
- 05-09· 《富士康十二连跳在这以