3月 26, 2010

Java Graphics1

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

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;
int pieceH = height / piece;

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

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

沒有留言:

張貼留言

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