dcsimg
June 19, 2018
Hot Topics:

User Code: Want to Draw a Rectangle Quickly?

  • December 7, 2001
  • By Sergey V.
  • Send Email »
  • More Articles »

You may be as surprised as me, but g.drawRoundRect(....) is 1.5 times faster than g.drawRect(....).

Yes, because one of them is completely native.

Hey, Sun, what is g.drawRect(....) for?


import java.awt.*; 

import java.awt.event.*; 

public class Class1 extends Frame implements ActionListener  

            {

            public void paint(Graphics g)

                        {

                        super.paint(g);

                        long t=System.currentTimeMillis();

                        for(int i=0;i<10000;i++)

                                   {

                                   g.drawRect(10,70,100,50); 

                                   }

                        t=System.currentTimeMillis()-t;

                        g.drawString(String.valueOf(t),10,70);

                        

                        t=System.currentTimeMillis();

                        for(int i=0;i<10000;i++)

                                   {

                                   g.drawRoundRect(10,130,100,50,0,0); 

                                   }

                        t=System.currentTimeMillis()-t;

                        g.drawString(String.valueOf(t),10,130);

                        }

 

            public void actionPerformed(ActionEvent p1)

                        {

                        repaint(0,10,200,300);

                        }

            

            public static void main (String[] args)

                        {

                        Class1 c=new Class1();

                        c.setSize(300,300);

                        c.setLayout(new BorderLayout());

                        Button b=new Button("Refresh");

                        c.add(BorderLayout.SOUTH , b);

                        b.addActionListener(c);

                        c.show();

                        }

 

            }





Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date