Java雷達掃描圖__JAVA

來源:互聯網
上載者:User

上圖,上代碼



package demo;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Composite;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.RenderingHints;import java.awt.geom.Arc2D;import java.awt.geom.Ellipse2D;import javax.swing.JComponent;import javax.swing.JFrame;import blade.paint.FanShapedGradientPaint;/** *  * @author Administrator *  */public class RadarDemo extends JComponent {public static void main(String argv[]) {JFrame frame = new JFrame();frame.setContentPane(new RadarDemo());frame.setSize(800, 600);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}@Overridepublic void paintComponent(Graphics g) {Graphics2D g2d = (Graphics2D) g;g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);paintBackground(g);paintRadarRing(g);paintFanShapedGradient(g);}protected void paintBackground(Graphics g) {g.setColor(Color.black);g.fillRect(0, 0, this.getWidth(), this.getHeight());}protected void paintRadarRing(Graphics g) {Graphics2D g2d = (Graphics2D) g;g.setColor(Color.green);Dimension d = this.getSize();double radius = Math.min(d.width, d.height) / 2;for (int r = 1; r <= 5; r++) {double R = r * radius / 5;double x = d.width / 2 - R;double y = d.height / 2 - R;Ellipse2D ellipse = new Ellipse2D.Double(x, y, R * 2, R * 2);g2d.draw(ellipse);}}protected void paintFanShapedGradient(Graphics g) {Graphics2D g2d = (Graphics2D) g;Composite oldComp = g2d.getComposite();AlphaComposite comp = AlphaComposite.getInstance(3, 0.5f);g2d.setComposite(comp);Dimension d = this.getSize();double radius = Math.min(d.width, d.height) / 2;double x = (d.width - radius * 2) / 2;double y = (d.height - radius * 2) / 2;FanShapedGradientPaint paint = new FanShapedGradientPaint(x, y, Math.PI / 2, Math.PI / 2, radius, Color.green,Color.black);g2d.setPaint(paint);Arc2D arc = new Arc2D.Double(x, y, radius * 2, radius * 2, 90, 90, Arc2D.PIE);g2d.fill(arc);g2d.setComposite(oldComp);}}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.