77_游戏项目_加载窗口_画图形_加载图片_编程中坐标基本知识

来源:互联网 发布:js简繁体切换 编辑:程序博客网 时间:2024/06/05 07:50
package com.zhushen.Test;import java.awt.Color;import java.awt.Font;import java.awt.Frame;import java.awt.Graphics;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;/** * 游戏窗口类 * @author zhushen * */public class GameFrame extends Frame {    private static final long serialVersionUID = 1L;    /**     * 加载游戏窗口     * @param x     * @param y     * @param width     * @param height     */    public void launchFrame(int x,int y,int width,int height){        setSize(width,height);        setLocation(x,y);        setVisible(true);        addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent e){                System.exit(0);            }        }) ;        }    /**     * 在窗口里面画元素     */    public void paint(Graphics g){    g.drawLine(100, 100, 300, 300);    g.drawRect(100, 100, 200, 200);    g.drawOval(100, 100, 200, 200);//根据外切矩形画圆(椭圆同理)    Font f=new Font("宋体",Font.BOLD,20);    g.setFont(f);    g.drawString("我是北京交通大学朱燊", 200, 200);//画一个字符串    g.fillRect(100, 100, 20, 20);//填充一个矩形    Color c=g.getColor();    g.setColor(Color.red);    g.fillOval(300, 300, 30, 30);//填充一个圆    g.setColor(c);    }    public static void main(String[] args) {        GameFrame gf=new GameFrame();        gf.launchFrame(100,100,500,500);    }}
原创粉丝点击