久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='mBe9m'></tfoot>
<i id='mBe9m'><tr id='mBe9m'><dt id='mBe9m'><q id='mBe9m'><span id='mBe9m'><b id='mBe9m'><form id='mBe9m'><ins id='mBe9m'></ins><ul id='mBe9m'></ul><sub id='mBe9m'></sub></form><legend id='mBe9m'></legend><bdo id='mBe9m'><pre id='mBe9m'><center id='mBe9m'></center></pre></bdo></b><th id='mBe9m'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mBe9m'><tfoot id='mBe9m'></tfoot><dl id='mBe9m'><fieldset id='mBe9m'></fieldset></dl></div>

  • <legend id='mBe9m'><style id='mBe9m'><dir id='mBe9m'><q id='mBe9m'></q></dir></style></legend>

      1. <small id='mBe9m'></small><noframes id='mBe9m'>

          <bdo id='mBe9m'></bdo><ul id='mBe9m'></ul>
      2. Java - 畫一個(gè)三角形

        Java - draw a triangle(Java - 畫一個(gè)三角形)
          <tbody id='PvCRn'></tbody>

          <legend id='PvCRn'><style id='PvCRn'><dir id='PvCRn'><q id='PvCRn'></q></dir></style></legend>

              <i id='PvCRn'><tr id='PvCRn'><dt id='PvCRn'><q id='PvCRn'><span id='PvCRn'><b id='PvCRn'><form id='PvCRn'><ins id='PvCRn'></ins><ul id='PvCRn'></ul><sub id='PvCRn'></sub></form><legend id='PvCRn'></legend><bdo id='PvCRn'><pre id='PvCRn'><center id='PvCRn'></center></pre></bdo></b><th id='PvCRn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PvCRn'><tfoot id='PvCRn'></tfoot><dl id='PvCRn'><fieldset id='PvCRn'></fieldset></dl></div>
            • <small id='PvCRn'></small><noframes id='PvCRn'>

                <tfoot id='PvCRn'></tfoot>

                • <bdo id='PvCRn'></bdo><ul id='PvCRn'></ul>
                  本文介紹了Java - 畫一個(gè)三角形的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  嘿,我知道繪制橢圓/矩形并使用填充它很簡(jiǎn)單

                  Hey I know that it is simple to draw oval/rectangle and fill it using

                  g.fillOval(30, 40, 20, 20);
                  

                  但是如何畫一個(gè)三角形呢?最好有隨機(jī)坐標(biāo).

                  but how to draw a triangle? It would be the best if it would have random coordinates.

                  推薦答案

                  根據(jù)您的需要,至少有兩種基本方法可以實(shí)現(xiàn)這一目標(biāo).

                  There are at least two basics ways you can achieve this, based on your needs.

                  您可以使用 Polygon 或者你可以使用 2D Graphics Shape API

                  您可能會(huì)選擇哪一種取決于您的要求.Polygon 要求您提前知道點(diǎn)在 3D 空間中的位置,而 Shape API 讓您可以更自由地定義形狀,而無(wú)需事先關(guān)心位置.

                  Which you might choose comes down to your requirements. Polygon requires you to know, in advance the position of the points within 3D space, where the Shape API gives you more freedom to define the shape without caring about the position in advance.

                  這使得 Shape API 更加靈活,因?yàn)槟梢远x一次形狀,然后根據(jù)需要簡(jiǎn)單地轉(zhuǎn)換 Graphics 上下文并重新繪制它.

                  This makes the Shape API more flexible, in that you can define the shape once and simply translate the Graphics context as needed and repaint it.

                  例如...

                  紅色是Polygon,綠色是Shape,翻譯成位置...

                  Red is a Polygon, green is a Shape, which is translated into position...

                  import java.awt.BorderLayout;
                  import java.awt.Color;
                  import java.awt.Dimension;
                  import java.awt.EventQueue;
                  import java.awt.Graphics;
                  import java.awt.Graphics2D;
                  import java.awt.Polygon;
                  import java.awt.geom.Path2D;
                  import java.awt.geom.Point2D;
                  import javax.swing.JFrame;
                  import javax.swing.JPanel;
                  import javax.swing.UIManager;
                  import javax.swing.UnsupportedLookAndFeelException;
                  
                  public class TriangleTest {
                  
                      public static void main(String[] args) {
                          new TriangleTest();
                      }
                  
                      public TriangleTest() {
                          EventQueue.invokeLater(new Runnable() {
                              @Override
                              public void run() {
                                  try {
                                      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                                  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                                  }
                  
                                  JFrame frame = new JFrame("Testing");
                                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                  frame.setLayout(new BorderLayout());
                                  frame.add(new TestPane());
                                  frame.pack();
                                  frame.setLocationRelativeTo(null);
                                  frame.setVisible(true);
                              }
                          });
                      }
                  
                      public class TestPane extends JPanel {
                  
                          private TriangleShape triangleShape;
                          private Polygon poly;
                  
                          public TestPane() {
                              triangleShape = new TriangleShape(
                                      new Point2D.Double(50, 0),
                                      new Point2D.Double(100, 100),
                                      new Point2D.Double(0, 100)
                              );
                  
                              poly = new Polygon(
                                      new int[]{50, 100, 0},
                                      new int[]{0, 100, 100},
                                      3);
                          }
                  
                          @Override
                          public Dimension getPreferredSize() {
                              return new Dimension(200, 200);
                          }
                  
                          @Override
                          protected void paintComponent(Graphics g) {
                              super.paintComponent(g);
                              Graphics2D g2d = (Graphics2D) g.create();
                              g2d.setColor(Color.RED);
                              g2d.fill(poly);
                  
                              g2d.setColor(Color.GREEN);
                              g2d.translate(50, 100);
                              g2d.fill(triangleShape);
                              g2d.dispose();
                          }
                      }
                  
                      public class TriangleShape extends Path2D.Double {
                  
                          public TriangleShape(Point2D... points) {
                              moveTo(points[0].getX(), points[0].getY());
                              lineTo(points[1].getX(), points[1].getY());
                              lineTo(points[2].getX(), points[2].getY());
                              closePath();
                          }
                  
                      }
                  
                  }
                  

                  這篇關(guān)于Java - 畫一個(gè)三角形的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測(cè) 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語(yǔ)句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個(gè)隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲(chǔ)為 int?)
                  <legend id='uTKzB'><style id='uTKzB'><dir id='uTKzB'><q id='uTKzB'></q></dir></style></legend>
                  • <i id='uTKzB'><tr id='uTKzB'><dt id='uTKzB'><q id='uTKzB'><span id='uTKzB'><b id='uTKzB'><form id='uTKzB'><ins id='uTKzB'></ins><ul id='uTKzB'></ul><sub id='uTKzB'></sub></form><legend id='uTKzB'></legend><bdo id='uTKzB'><pre id='uTKzB'><center id='uTKzB'></center></pre></bdo></b><th id='uTKzB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uTKzB'><tfoot id='uTKzB'></tfoot><dl id='uTKzB'><fieldset id='uTKzB'></fieldset></dl></div>
                      <tbody id='uTKzB'></tbody>

                    <small id='uTKzB'></small><noframes id='uTKzB'>

                        <bdo id='uTKzB'></bdo><ul id='uTKzB'></ul>
                        <tfoot id='uTKzB'></tfoot>

                          1. 主站蜘蛛池模板: 一a一片一级一片啪啪 | 久草色视频 | 国产精品永久久久久 | 欧美黑人国产人伦爽爽爽 | 国产成人精品久久二区二区91 | 国产精品视频导航 | 男女性毛片| 亚洲一区二区三区免费在线 | 午夜精品久久久久久久99黑人 | 国产精品久久久久久久久免费樱桃 | 精品国产精品一区二区夜夜嗨 | 365夜爽爽欧美性午夜免费视频 | 欧美无乱码久久久免费午夜一区 | 欧美综合一区二区三区 | 国产精品视频一区二区三区, | 亚洲精品一区二区在线观看 | 91精产国品一二三区 | 午夜在线 | 蜜桃av人人夜夜澡人人爽 | 久久久久久亚洲精品 | 久久久久久久av | 久久精品免费观看 | 91欧美精品成人综合在线观看 | 91精品久久久久久久久 | 欧美一级在线观看 | 国产98色在线 | 成人欧美一区二区三区黑人孕妇 | 欧美色人| 91精品国产综合久久婷婷香蕉 | 日韩中文字幕在线视频 | 国产丝袜人妖cd露出 | 国产乱xxav | 午夜精品久久久久久久久久久久久 | 欧美精品在线一区 | 青青草av| 99亚洲精品 | 中文字幕亚洲精品 | 成人福利在线视频 | 欧美亚洲国语精品一区二区 | 国产精品毛片一区二区在线看 | 精品麻豆剧传媒av国产九九九 |