Javaswing also stunning two: ring-ring Phase sets

Source: Internet
Author: User

I. Preamble

There has been a long-standing debate about "Java does not do well on the desktop." Although swing and java2d have more than 10 years of history, there are many open source swing components such as Jide, Jgoodies, Twaver, but it is still not easy to use Java as a desktop program. This "Java also stunning" series of articles, is to pass some simple and vivid examples, and everyone together to understand Java, explore swing. In fact, you just need a little more creativity, a little more patience, your Java program can also be "stunning"! This article will take you to the amazing journey of Java.

Second, three-dimensional casing effect

In network communication, the "bearer" relationship between protocols is often expressed. For example, an IP protocol can be hosted on SDH or hosted on an ATM protocol as a high-level protocol. Similarly, IP as a protocol can also host more high-level protocols, such as Voice over IP, and even telecommunications everything over IP concept. In performance, the use of nested three-dimensional casing to express the agreement of the "load" is more appropriate (pictured below).

The actual implementation is simple, the main code is as follows:

import java.awt.*;


import java.awt.geom.*;


import javax.swing.*;





import twaver.*;





public class Piplecomponent extends JComponent {





public void Paint (Graphics g) {


graphics2d g2d = (graphics2d) g;


G2d.setrenderinghint (renderinghints.key_antialiasing, renderinghints.value_antialias_on);


Shape parenthollowshape=createpiple (G2d,100,100,200,200,twaverutil.getrandomcolor (), NULL);


createpiple (G2d,120,120,280,40,twaverutil.getrandomcolor (), parenthollowshape);


createpiple (G2d,130,170,310,40,twaverutil.getrandomcolor (), parenthollowshape);


createpiple (G2d,140,220,290,50,twaverutil.getrandomcolor (), parenthollowshape);


createpiple (G2d,130,190,300,30,twaverutil.getrandomcolor (), parenthollowshape);


     }





private Shape createpiple (graphics2d g2d,int x, int y, int width, int height,color color,shape PE) {


if (parenthollowshape!=null) {


Rectangle bounds=parenthollowshape.getbounds ();


Rectangle rightclip=new Rectangle (bounds.x+bounds.width/2,bounds.y,3000,bounds.height);


Area clip=new Area (parenthollowshape);


Clip.add (New Area (Rightclip));


g2d.setclip (clip);


         }


int circlewidth = HEIGHT/3;


gradientpaint paint = new Gradientpaint (x,


y,


Color.brighter (),


x,


y + (int) (height * 0.65),


Color.darker (),


true);


g2d.setpaint (paint);


Ellipse2d.double leftcircle = new Ellipse2d.double (X-CIRCLEWIDTH/2, y, circlewidth, height);


ellipse2d.double rightcircle = new Ellipse2d.double (x + width-circlewidth/2, y, circlewidth, height);





int thickness=4;


ellipse2d.double righthollowcircle = new Ellipse2d.double (Rightcircle.getx () +thickness,


rightcircle.gety () +thickness,


rightcircle.getwidth ()-thickness*2,


rightcircle.getheight ()-thickness*2);





Rectangle rect = new Rectangle (x, y, width, height);


Area area = new Area (leftcircle);


Area.add (New Area (rect));


Area.subtract (New Area (rightcircle));


G2d.fill (area);


G2d.setcolor (Color.darker ());


G2d.fill (rightcircle);





paint = new Gradientpaint (x,


y,


Color.darkgray,


x,


y + (int) (height * 0.4),


Color.lightgray,


true);





g2d.setpaint (paint);


G2d.fill (righthollowcircle);





g2d.setclip (NULL);





return righthollowcircle;


     }





public static void Main (string[] args) {


JFrame frame = new JFrame ();


frame.setdefaultcloseoperation (jframe.exit_on_close);


frame.setsize (800, 600);


Frame.add (New Piplecomponent ());


frame.setvisible (TRUE);


     }


}

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.