Java Learning Java 2D Graphics drawing

Source: Internet
Author: User

Recently there has been no time to write a blog, things more, quiet heart, things go with its natural good, and some things I do not understand why it will become so, you think you pay the most precious, but perhaps others do not like. Forget it, do not think much, let it be natural.

Java does not keep up with C + + in graphic drawing, but I think Java has some advantages in graphics, but for large desktop games, it is impossible to estimate even smoothness.

Here's the code for the most recent write:

Package Draw;import java.awt.*;import javax.swing.*;import java.awt.geom.*;p ublic class drawtest{public static void Main (string[] args) {Eventqueue.invokelater (new Runnable () {public void run () {JFrame frame=new drawframe (); Frame.settitle ("Draw"); Frame.setdefaultcloseoperation (jframe.exit_on_close); frame.setvisible (True);}});}} Class Drawframe extends Jframe{public Drawframe () {Add (New Drawcomponent ());p ack ();}} Class Drawcomponent extends jcomponent{private static final int default_width=400;private static final int default_height =400;public void Paintcomponent (Graphics g) {graphics2d g2= (graphics2d) g;double leftx=100;double topy=100;double width =200;double height=150; Rectangle2D rect=new rectangle2d.double (leftx,topy,width,height); G2.draw (rect); Ellipse2d ellipse=new ellipse2d.double (); Ellipse.setframe (rect); G2.draw (ellipse); G2.draw (New Line2d.double (LeftX, topy,width,height));d ouble Centerx=rect.getcenterx ();d ouble centery=rect.getcentery ();d ouble radius=150; Ellipse2d circle=new Ellipse2d.dOuble (Centerx,centery,centerx+radius,centery+radius); Circle.setframefromcenter (CenterX,centerY,centerX+radius, Centery+radius); G2.draw (circle);} Public Dimension getPreferredSize () {return new Dimension (default_width,default_height);}

  

This is, I was thinking about using Java to do the GUI, and then to invoke my previous project to write some of the DLL files, so the teacher let me do the interface is very easy, the mentor let me use OpenGL interface, I feel that this is not to develop a micro swing or WPF ...

Java Learning Java 2D Graphics drawing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.