/*
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 );
}
}