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

  • <small id='cakJy'></small><noframes id='cakJy'>

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

      • <bdo id='cakJy'></bdo><ul id='cakJy'></ul>
      <tfoot id='cakJy'></tfoot>

      1. 在 Java 中繪制謝爾賓斯基三角形

        Drawing Sierpinski#39;s Triangle in Java(在 Java 中繪制謝爾賓斯基三角形)
      2. <legend id='kzywG'><style id='kzywG'><dir id='kzywG'><q id='kzywG'></q></dir></style></legend>

            <tbody id='kzywG'></tbody>

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

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

                  本文介紹了在 Java 中繪制謝爾賓斯基三角形的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在繪制謝爾賓斯基三角形(或謝爾賓斯基墊片)的代碼時遇到了一些問題,但我不確定是什么問題.繪制三角形的線,然后繪制所有分形,然后消失.幫忙?

                  import javax.swing.*;導入 java.awt.*;公共類 SierpinskiGasket 擴展 JFrame {點 x=新點(5,545),y=新點(300,25),z=新點(605,545),當前=x,目標;私人int計數=0;公共SierpinskiGasket(){超級(謝爾賓斯基墊片");設置大小(610,550);設置默認關閉操作(JFrame.EXIT_ON_CLOSE);getContentPane().setBackground(Color.WHITE);setLocationRelativeTo(null);可調整大小(假);設置可見(真);}公共無效油漆(圖形g){super.paint(g);如果(計數==0){g.drawLine(x.x,x.y,y.x,y.y);g.drawLine(x.x,x.y,z.x,z.y);g.drawLine(z.x,z.y,y.x,y.y);} 別的 {而(計數<10000){int 選擇=(int)(Math.random()*3);開關(選擇){案例0:目標=x;休息;案例1:目標=y;休息;案例2:目標=z;休息;默認值:System.exit(0);}當前=中點(當前,目標);g.drawRect(current.x,current.y,5,5);重繪();計數++;}}計數++;}公共點中點(點a,點b){返回新點((Math.round(a.x+b.x)/2),(Math.round(a.y+b.y)/2));}公共靜態無效主要(字符串[]參數){新的謝爾賓斯基墊片();}}

                  解決方案

                  1. 不要從頂級容器(如 JFrame)擴展,你不會為它添加任何好處.
                  2. 避免繪制到頂級容器.而是使用 JPanel 之類的東西.
                  3. 避免覆蓋 paint,改用 paintComponent.有關詳細信息,請參閱

                    I'm having some issues with my code to draw a Sierpinski's Triangle (or Sierpinski's Gasket), but I'm not sure what the problem is. The lines for the triangle are drawn, then all the fractals, then it disappears. Help?

                    import javax.swing.*;
                    import java.awt.*;
                    
                    public class SierpinskiGasket extends JFrame {
                    
                    Point x=new Point(5,545),
                          y=new Point(300,25),
                          z=new Point(605,545),
                          current=x, target;
                    private int count=0;
                    
                    public SierpinskiGasket () {
                        super("Sierpinski Gasket");
                        setSize(610,550);
                        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        getContentPane().setBackground(Color.WHITE);
                        setLocationRelativeTo(null);
                        setResizable(false);
                        setVisible(true);
                    }
                    
                    public void paint(Graphics g) {
                        super.paint(g);
                        if(count==0) {
                        g.drawLine(x.x,x.y,y.x,y.y);
                        g.drawLine(x.x,x.y,z.x,z.y);
                        g.drawLine(z.x,z.y,y.x,y.y);
                        } else {
                            while(count<10000) {
                                int choice=(int)(Math.random()*3);
                                switch(choice) {
                                    case 0: target=x; break;
                                    case 1: target=y; break;
                                    case 2: target=z; break;
                                    default: System.exit(0);
                                }
                                current=midpoint(current,target);
                                g.drawRect(current.x,current.y,5,5);
                                repaint();
                                count++;
                            }
                        }
                        count++;
                    }
                    
                    public Point midpoint(Point a, Point b) {
                        return new Point((Math.round(a.x+b.x)/2),
                                         (Math.round(a.y+b.y)/2));
                    }
                    
                    public static void main(String[] args) {
                        new SierpinskiGasket();
                    }
                    }
                    

                    解決方案

                    1. Don't extend from a top level container (like JFrame), you're not adding anything of benefit to it.
                    2. Avoid painting to top level containers. Instead use something like JPanel.
                    3. Avoid overriding paint, use paintComponent instead. See Performing Custom Painting for more details

                    This is not how paint works (and I'm not going to try to rewrite your code to make it).

                    Paint is called in response to a number of events when the repaint system decides that part or whole of the UI needs to be updated. Paints are destructive, that is, when paint is called, the Graphics will be completely refreshed, requiring you to "rebuild" the output from scratch.

                    Instead.

                    Write a recursive algorithm that can paint to something like BufferedImage and draw that within the paintComponent...

                    Updated

                    Painting in Swing is controlled by the RepaintManager, it is it's responsibility to determine what and when to repaint the screen. You seem to be thinking the paint is something your control, when it's not.

                    You need to either be prepared to completely repaint the UI or have a buffer prepared that you can paint onto the UI, depending on your needs.

                    import java.awt.BorderLayout;
                    import java.awt.Dimension;
                    import java.awt.EventQueue;
                    import java.awt.Graphics;
                    import java.awt.Graphics2D;
                    import java.awt.Rectangle;
                    import java.awt.geom.AffineTransform;
                    import java.awt.geom.Path2D;
                    import javax.swing.JFrame;
                    import javax.swing.JPanel;
                    import javax.swing.UIManager;
                    import javax.swing.UnsupportedLookAndFeelException;
                    
                    public class SierpinskisGasket {
                    
                        public static void main(String[] args) {
                            new SierpinskisGasket();
                        }
                    
                        public SierpinskisGasket() {
                            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 {
                    
                            public TestPane() {
                            }
                    
                            @Override
                            public Dimension getPreferredSize() {
                                return new Dimension(200, 200);
                            }
                    
                            @Override
                            protected void paintComponent(Graphics g) {
                                super.paintComponent(g);
                                Graphics2D g2d = (Graphics2D) g.create();
                                BaseShape base = new BaseShape(Math.min(getWidth(), getHeight()));
                                Rectangle bounds = base.getBounds();
                                int x = (getWidth() - bounds.width) / 2;
                                int y = (getHeight() - bounds.height) / 2;
                                base.transform(AffineTransform.getTranslateInstance(x, y));
                                g2d.fill(base);
                                g2d.dispose();
                            }
                        }
                    
                        public class BaseShape extends Path2D.Float {
                    
                            public BaseShape(float size) {
                    
                                float subSize = size / 2f;
                                Triangle top = new Triangle(subSize);
                                top.transform(AffineTransform.getTranslateInstance((size - subSize) / 2, 0));
                                append(top, false);
                    
                                Triangle left = new Triangle(subSize);
                                left.transform(AffineTransform.getTranslateInstance(0, subSize));
                                append(left, false);
                    
                                Triangle right = new Triangle(subSize);
                                right.transform(AffineTransform.getTranslateInstance(subSize, subSize));
                                append(right, false);
                    
                            }
                    
                        }
                    
                        public class Triangle extends Path2D.Float {
                    
                            public Triangle(float size) {
                    
                                moveTo(size / 2f, 0);
                                lineTo(size, size);
                                lineTo(0, size);
                                closePath();
                    
                            }
                    
                        }
                    
                    }
                    

                    You should never be calling anything from paint that could alter the state of the UI and trigger another repaint, otherwise you are going to end up in a end cycle of repaints that will eventually consume your CPU.

                    You should also take a look at Painting in AWT and Swing

                    這篇關于在 Java 中繪制謝爾賓斯基三角形的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

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

                      <tbody id='5AzuB'></tbody>
                      <tfoot id='5AzuB'></tfoot>

                        <legend id='5AzuB'><style id='5AzuB'><dir id='5AzuB'><q id='5AzuB'></q></dir></style></legend>

                        <small id='5AzuB'></small><noframes id='5AzuB'>

                        • <bdo id='5AzuB'></bdo><ul id='5AzuB'></ul>

                            主站蜘蛛池模板: 中文字幕日本一区二区 | 91国内在线观看 | 日韩久久久久 | 天堂一区二区三区 | 久久美女视频 | 午夜免费在线观看 | 久久高清 | 91福利影院| www.免费看片.com | 日韩高清中文字幕 | 欧州一区二区三区 | 成人免费视频观看视频 | 国产精品一区在线播放 | 天天干.com | 国产一区二区三区在线 | 黄色片网此| 国产午夜高清 | 福利视频日韩 | 成人网在线看 | 国产在线麻豆精品入口 | 97影院2| 一级在线| 黑人精品欧美一区二区蜜桃 | 欧美最猛性xxxxx亚洲精品 | 久久高清国产视频 | 视频一区在线 | 亚洲成人精品久久久 | 亚洲小视频在线播放 | 午夜影院 | 成人三级在线观看 | 亚洲国产二区 | 青青草在线视频免费观看 | 久草视频在 | 91色站| 欧美日韩在线综合 | 亚洲日本中文 | 一区二区视频 | 九九看片| 久久国产成人午夜av影院武则天 | 久久精品国产一区二区电影 | 777zyz色资源站在线观看 |