📄 j_graphics.java.bak
字号:
// ////////////////////////////////////////////////////////
//
// J_Graphics.java
//
// Created by Jun-Hai Yong, on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
// An example of Graphics.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
// Jun-Hai Yong. Programming in Java.
// Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
// 雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
public class J_Graphics extends JApplet
{
public void paint(Graphics g)
{
Graphics2D g2d= (Graphics2D)g;
// Fill a circle with gradient paint
g2d.setPaint( new GradientPaint( 5, 30, Color.red, 35, 100, Color.yellow, true ) );
g2d.fill( new Ellipse2D.Double( 20, 20, 100, 100 ) );
// 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
// Fill a rectangle with the texture
g2d.setPaint( new TexturePaint( buffImage, new Rectangle( 10, 10 ) ) );
g2d.fill( new Rectangle2D.Double( 160, 20, 100, 100 ) );
} // End of method: paint
} // End of class: J_Graphics
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -