3月 26, 2010

Java Graphics2

Java Graphics2
從四角落發射的網狀圖形

import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanel extends JPanel
{
public void paintComponent( Graphics g )
{
super.paintComponent( g );
int counter = 1;
final int piece = 15;
int width = getWidth();
int height = getHeight();
int pieceW = width / piece; //單位寬x
int pieceH = height / piece; //單位高y

while( counter < piece ) { g.drawLine( 0, pieceH*(counter-1), pieceW*counter, height ); //左上 g.drawLine( pieceW*(counter-1), height, width, pieceH*(piece-counter) ); //左下 g.drawLine( pieceW*(piece-counter+1), 0, 0, pieceH*counter ); //右上 g.drawLine( width, pieceH*(piece-counter+1), pieceW*(piece-counter), 0 ); //右下 counter++; } } }

以上為使用 Java 所繪製出來的圖形程式碼,僅供學習參考
程式碼是我自己寫出來的,如有雷同、純屬巧合
如有任何疑問,歡迎留言一同討論!

沒有留言:

張貼留言

歡迎留言~登入身分再留言方便後續意見交流喔!
當然,沒登入也可以留言!