1. 程式人生 > >Java 遊戲開發 模板1

Java 遊戲開發 模板1

package com.asmn.sudoku;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainGame extends JPanel {

	static int width, height;
	//螢幕縮放倍數
	int multiple;
	
	public MainGame(){
		multiple = 2;
		width = 1920/multiple;
		height = 1080/multiple;
	}
	
	@Override
	public void paint(Graphics gl){
		gl.setColor(Color.BLUE);
		gl.fillRect(0, 0, width, height);
	}
	
	public static void main(String[] args) {
		JFrame window = new JFrame();
		MainGame game = new MainGame();
		window.setSize(width, height);
		window.setLocationRelativeTo(null);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.add(game);
		window.setVisible(true);
	}

}

JFrame作為顯示的視窗容器,JPanel則是容器裡面的資源