码迷,mamicode.com
首页 > 编程语言 > 详细

根据点画线java

时间:2015-06-19 18:27:20      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

 1 package com.yang;
 2 
 3 import java.awt.Color;
 4 import java.awt.Graphics;
 5 import java.util.ArrayList;
 6 import java.util.List;
 7 
 8 import javax.swing.JFrame;
 9 import javax.swing.JPanel;
10 
11 public class drawlineforspline extends JFrame{
12     
13     private static final long serialVersionUID = 1L;
14     static List <mypoint>plist;
15     public static class mypoint{
16         int x;
17         int y;
18         public mypoint(int x,int y){
19             this.x=x;
20             this.y=y;
21         }
22     }
23     public drawlineforspline(){
24         init();
25     }
26     public drawlineforspline(ArrayList plist){
27         init();
28         this.plist=plist;
29          
30     }
31     private void init(){
32      
33         this.setTitle("drawline");
34         this.setBounds(200, 200, 500, 400);
35         this.setBackground(Color.white);
36         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
37         this.setLocationRelativeTo(null);
38         this.setVisible(true); 
39         
40         plist =new ArrayList();
41         plist.add(new mypoint(50,80));
42         plist.add(new mypoint(50,120));
43         plist.add(new mypoint(80,50));
44         plist.add(new mypoint(150,10));
45         plist.add(new mypoint(180,80));
46         plist.add(new mypoint(230,200));
47         
48     }
49  
50     
51     public class Mypanel extends JPanel{     
52         public void paint(Graphics g){
53             mypoint fromP=new mypoint(50,80);
54             mypoint toP=new mypoint(370,240);
55             for(int i=0;i<plist.size()-1;i++){
56                 g.drawLine(plist.get(i).x, plist.get(i).y, plist.get(i+1).x, plist.get(i+1).y);
57             }
58         }
59     }
60     
61     public static void main(String[] args) {
62         drawlineforspline d=new drawlineforspline();
63         Mypanel myp=d.new Mypanel();
64         d.add(myp);
65     }
66 
67 }

 

根据点画线java

标签:

原文地址:http://www.cnblogs.com/rojas/p/4589195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!