根据点画线java
阅读原文时间:2023年07月10日阅读:3

package com.yang;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class drawlineforspline extends JFrame{

 private static final long serialVersionUID = 1L;  
 static List <mypoint>plist;  
 public static class mypoint{  
     int x;  
     int y;  
     public mypoint(int x,int y){  
         this.x=x;  
         this.y=y;  
     }  
 }  
 public drawlineforspline(){  
     init();  
 }  
 public drawlineforspline(ArrayList plist){  
     init();  
     this.plist=plist;

 }  
 private void init(){

     this.setTitle("drawline");  
     this.setBounds(200, 200, 500, 400);  
     this.setBackground(Color.white);  
     this.setDefaultCloseOperation(JFrame.EXIT\_ON\_CLOSE);  
     this.setLocationRelativeTo(null);  
     this.setVisible(true); 

     plist =new ArrayList();  
     plist.add(new mypoint(50,80));  
     plist.add(new mypoint(50,120));  
     plist.add(new mypoint(80,50));  
     plist.add(new mypoint(150,10));  
     plist.add(new mypoint(180,80));  
     plist.add(new mypoint(230,200));

 }

 public class Mypanel extends JPanel{  
     public void paint(Graphics g){  
         mypoint fromP=new mypoint(50,80);  
         mypoint toP=new mypoint(370,240);  
         for(int i=0;i<plist.size()-1;i++){  
             g.drawLine(plist.get(i).x, plist.get(i).y, plist.get(i+1).x, plist.get(i+1).y);  
         }  
     }  
 }

 public static void main(String\[\] args) {  
     drawlineforspline d=new drawlineforspline();  
     Mypanel myp=d.new Mypanel();  
     d.add(myp);  
 }

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章