The first step of Java [11]

Source: Internet
Author: User
/*
Create an application displaynames that displays your name in every
Even-numbered font from size 4 to 24. Make the color red.
*/

Import javax. Swing .*;
Import java. AWT .*;

Public class displaynames
{
Public static void main (string [] ARGs)
{
Simpleframe frame = new simpleframe ();
Frame. setdefaclocloseoperation (jframe. exit_on_close );
Frame. settitle ("lab #8-displaynames ");
Frame. setlocation (700,100 );
Frame. Show ();
}
}

Class simpleframe extends jframe
{
Public simpleframe ()
{
Setsize (default_width, default_height );
Fillpanel = new fillpanel ();
Container contentpane = getcontentpane ();
Contentpane. Add (panel );
}

Public static final int default_width = 300;
Public static final int default_height = 600;
}

Class fillpanel extends jpanel
{
Public void paintcomponent (Graphics g)
{
Super. paintcomponent (g );
Graphics2d g2 = (graphics2d) g;
G2.setcolor (color. Red );
For (INT I = 4; I <= 24; I ++)
{
Font d = new font (" 文 ", Font. Plain, I );
G2.setfont (d );
G2.drawstring ("Daniel, 88250", 20, 30 + I * 20 );
}

}
}
/*
Create an application shapestest that displays various shapes in various colors.
· A line in black color
· A circle in green color
· A rectangle in orange color
*/

Import javax. Swing .*;
Import java. AWT .*;
Import java. AWT. Geom .*;

Public class shapestest
{
Public static void main (string [] ARGs)
{
Simpleframe frame = new simpleframe ();
Frame. setdefaclocloseoperation (jframe. exit_on_close );
Frame. settitle ("lab #8-shapestest ");
Frame. setlocation (700,200 );
Frame. Show ();
}
}

Class simpleframe extends jframe
{
Public simpleframe ()
{
Setsize (default_width, default_height );
Fillpanel = new fillpanel ();
Container contentpane = getcontentpane ();
Contentpane. Add (panel );
}

Public static final int default_width = 300;
Public static final int default_height = 200;
}

Class fillpanel extends jpanel
{
Public void paintcomponent (Graphics g)
{
Super. paintcomponent (g );
Graphics2d g2 = (graphics2d) g;

Ellipse2d E = new ellipse2d. Double (100.0, 100.0, 40.0, 40.0 );
G2.setcolor (color. Green );
G2.fill (E );

G2.setstroke (New basicstroke (2, basicstroke. cap_square, basicstroke. join_round ));
Line2d L = new line2d. Double (100.0, 100.0, 30.0, 100.0 );
G2.setcolor (color. Black );
G2.draw (L );

Rectangle2d r = new rectangle2d. Double (40.0, 24.0, 50.0, 25.0 );
G2.setcolor (color. Orange );
G2.fill (R );
}
}

 

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.