📄 j_shapetest.java
字号:
// ////////////////////////////////////////////////////////
//
// J_ShapeTest.java
//
// ////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.applet.Applet;
interface J_Shape
{
public abstract void mb_draw(Graphics2D g); // This method cannot have body.
} // End of interface: J_Shape
class J_Circle implements J_Shape
{
public void mb_draw(Graphics2D g)
{
g.setPaint( new GradientPaint( 5, 30, Color.red, 35,
100, Color.yellow, true ) );
g.fill( new Ellipse2D.Double( 20, 20, 100, 100 ) );
} // End of method: mb_draw
} // End of class: J_Circle
class J_Square implements J_Shape
{
public void mb_draw(Graphics2D g)
{
// Create a texture
BufferedImage buffImage = new BufferedImage(
10, 10, BufferedImage.TYPE_INT_RGB );
Graphics2D gg = buffImage.createGraphics( );
gg.setColor( Color.yellow ); // draw in yellow
gg.fillRect( 0, 0, 10, 10 ); // draw a filled rectangle
gg.setColor( Color.blue ); // draw in black
gg.drawRect( 1, 1, 6, 6 ); // draw a rectangle
gg.setColor( Color.green ); // draw in blue
gg.fillRect( 1, 1, 3, 3 ); // draw a filled rectangle
gg.setColor( Color.red ); // draw in red
gg.fillRect( 4, 4, 3, 3 ); // draw a filled rectangle
// paint buffImage onto the JFrame
g.setPaint( new TexturePaint( buffImage, new Rectangle( 10, 10 ) ) );
g.fill( new Rectangle2D.Double( 160, 20, 100, 100 ) );
} // End of method: mb_draw
} // End of class: J_Square
public class J_ShapeTest extends Applet
{
public void paint(Graphics g)
{
Graphics2D g2d= (Graphics2D)g;
J_Shape entity = new J_Circle( );
entity.mb_draw(g2d);
entity = new J_Square( );
entity.mb_draw(g2d);
} // End of method: paint
} // End of class: J_ShapeTest
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -