【java版坦克大战---准备篇】 java 绘图

时间:2021-09-16 15:49:42

要写坦克大战当然要先画出坦克。java画图是基础。

package com.game;
import java.awt.*;
import javax.swing.*;
public class Pro_1 extends JFrame {
public static MyPanel mp=null;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Pro_1 pro_1 = new Pro_1();
pro_1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
mp = new MyPanel();
pro_1.add(mp);
pro_1.setSize(new Dimension(400,300));
pro_1.setTitle("Demo");
pro_1.setVisible(true);
}
} class MyPanel extends Panel{
public void paint(Graphics g){
super.paint(g);
g.drawOval(10, 10, 50, 50);
g.setColor(Color.blue);
g.setFont(new Font("华文彩云1",Font.BOLD,40));
g.drawImage(Toolkit.getDefaultToolkit().getImage("./loginbtn.jpg"), 60, 60, 85, 32,this);
g.drawString("hi,你好",40,50);
}
}