⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beautful arrow.txt

📁 画一个美观的箭头,有好多的可以学习的东西
💻 TXT
字号:
/** 
* @(#) ArraowLinePanel.java 
* 
* Copyright 2004 Opensource Develop Team. All rights reserved. 
*/ 

// package 
pakcage com.opensource.arrow; 

// import classes 
import java.awt.*; 
import java.swing.*; 
import java.awt.geom.*: 

/** 
* 在Panel上画一个箭头 
* 
* @author ODT 
* @version 1.0 22/04/2004 
* @see JPanel 
* @since 1.3 
*/ 
class ArrowLinePanel extends JPanel 
{ 
     // confirm the line position 
     Line2D line = new Line2D.Float(100f, 100f, 300f, 300f);  

     ArrowLinePanel() 
     { 
     setBackground(Color.white); 
     } 

     public void paintComponent(Graphics g) 
     { 
           super.paintComponent(g); 

           Graphics2D g2D = (Graphics2D) g; 
           g2D.setColor(Color.red); 
           g2D.draw(line); // draw line without arrow. 

           double x1 = line.getX1(); 
           double x2 = line.getX2(); 
           double y1 = line.getY1(); 
           double y2 = line.getY2(); 
           // compute the line's length 
           double length = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));  
           g2D.translate(x1, y1);  
           // compute the angle between line and X axis. 
           double roate = Math.atan((y2-y1)/(x2-x1));  
           // draw arrow 
           GeneralPath path = new GeneralPath(); 
           path.moveTo((float)length, 0); 
           path.lineTo((float)length - 10, -5); 
           path.lineTo((float)length - 7, 0); 
           path.lineTo((float)length - 10, 5); 
           path.lineTo((float)length, 0); 
           path.closePath(); 

           Area area = new Area(path); 
           g2D.fill(area); 
     } 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -