1 PackageCom.yang;2 3 ImportJava.awt.Color;4 ImportJava.awt.Graphics;5 Importjava.util.ArrayList;6 Importjava.util.List;7 8 ImportJavax.swing.JFrame;9 ImportJavax.swing.JPanel;Ten One Public classDrawlineforsplineextendsjframe{ A - Private Static Final LongSerialversionuid = 1L; - StaticList <mypoint>plist; the Public Static classmypoint{ - intx; - inty; - PublicMyPoint (intXinty) { + This. x=x; - This. y=y; + } A } at PublicDrawlineforspline () { - init (); - } - Publicdrawlineforspline (ArrayList plist) { - init (); - This. plist=plist; in - } to Private voidinit () { + - This. Settitle ("DrawLine"); the This. setbounds (200, 200, 500, 400); * This. SetBackground (color.white); $ This. Setdefaultcloseoperation (jframe.exit_on_close);Panax Notoginseng This. Setlocationrelativeto (NULL); - This. setvisible (true); the +Plist =NewArrayList (); APlist.add (NewMyPoint (50,80)); thePlist.add (NewMyPoint (50,120)); +Plist.add (NewMyPoint (80,50)); -Plist.add (NewMyPoint (150,10)); $Plist.add (NewMyPoint (180,80)); $Plist.add (NewMyPoint (230,200)); - - } the - Wuyi Public classMypanelextendsjpanel{ the Public voidPaint (Graphics g) { -MyPoint fromp=NewMyPoint (50,80); WuMyPoint top=NewMyPoint (370,240); - for(intI=0;i<plist.size () -1;i++){ AboutG.drawline (Plist.get (i). x, Plist.get (i). Y, Plist.get (i+1). x, Plist.get (i+1). y); $ } - } - } - A Public Static voidMain (string[] args) { +Drawlineforspline d=Newdrawlineforspline (); theMypanel Myp=d.NewMypanel (); - D.add (MYP); $ } the the}
Draw lines based on dots Java