java繪圖技術(一)

package 第一版;

import java.awt.*;

import javax.swing.*;
import javax.tools.Tool;

public class draw1 extends JFrame{
	MyPanel mp = null;
	public draw1() {
		mp = new MyPanel();
		this.add(mp);
		this.setSize(400, 300); // 設置框體大小
		this.setLocation(400,150); //設置框體顯示的位置
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 設置框體退出
		this.setVisible(true); // 顯示框體
	}
	public static void main(String[] args) {
		draw1 d = new draw1();
	}
}
// 我的畫板
// Graphics是一個很重要的畫圖的類,可以理解成一支毛筆
class MyPanel extends Panel{
	public void paint(Graphics g){ // 重寫paint函數,系統會自動調用函數
//		super.paint(g); 
//		g.drawOval(100, 10, 30, 30); // 畫圓
//		g.drawLine(30, 50, 40, 70); 
//		g.drawRect(50, 50, 40, 30); // 畫矩形
//		g.setColor(Color.blue); // 設置畫筆顏色
//		g.fillRect(100, 100, 40, 70); // 填充矩形
//		try{
//			Image im = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/2013-10-25-19.jpg"));
//			// 圖片放在src目錄下
//			g.drawImage(im, 90, 90, 200, 150, this);
//		}catch(Exception e){
//			System.out.println("yes");
//		}
		g.setColor(Color.RED);
		g.setFont(new Font("華文彩雲",Font.BOLD,30));
		g.drawString("祖國萬歲!", 100, 100);
		
	}
}

發佈了161 篇原創文章 · 獲贊 21 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章