jbuilder 100例 java源码学习,非常不错,有需要朋友下来
源代码在线查看: draw.java~8~
package line; import java.awt.*; import java.awt.event.*; import java.applet.*; public class draw extends Applet { Point spoint; Point points[]; int nump; boolean drawing = false; boolean isStandalone = false; /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } public void init(){ spoint=new Point(0,0); points=new Point[1000]; nump=0; drawing=false; } public boolean handleEvent(Event e){ switch(e.id){ case Event.MOUSE_DOWN : drawing = !drawing; if(drawing){ spoint.x=e.x; spoint.y=e.y; } return true; case Event.MOUSE_MOVE : if((drawing)&&(nump points[nump]=new Point(e.x,e.y); ++nump; repaint(); } return true; default: return false; } } public void paint(Graphics g){ int oldx=spoint.x; int oldy=spoint.y; for(int x=0;x g.drawLine(oldx,oldy,points[x].x,points[x].y); oldx=points[x].x; oldy=points[x].y; } } /**Construct the applet*/ public draw() { } /**Initialize the applet*/ /**Component initialization*/ private void jbInit() throws Exception { } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } }