标签:
a) 下载JDK(Java Development Kit)
b) 安装JDK、 JRE(Java Runtime environment)
c) 配置环境变量:
i. path(系统通过path指定的目录寻找相关的可执行文件!)
右键单击我的电脑à属性à高级à环境变量à修改path即可!
ii. classpath(系统通过classpath寻找类文件)
JDK1.5之后,可以不设置!
a) 下载
b) 解压即可
a) New Java Projectà只需要输入project name,回车即可!
a) 右键单击srcànew àClassà键入类名:BallGame
b) 输入代码:
public class BallGame { public static void main(String[] args){ System.out.println("我是尚学堂的高淇!"); } } |
c) 运行java程序的三种方式:
i. 右键单击àRun asàjava application
ii. Alt+shift+X,再按J
iii. Ctrl+F11
iv. 单击运行按钮
开始开发我们的小游戏
import java.awt.*; public class BallGame extends Frame {
void launchFrame(){ setSize(500, 300); setLocation(50, 50); setVisible(true); setTitle("尚学堂---张三作品"); setBackground(Color.black); }
public static void main(String[] args){ System.out.println("我是尚学堂的高淇!"); new BallGame().launchFrame(); } } |
在项目下新建images文件夹,将sun.jpg拷贝到images下面 |
import java.awt.*;
public class BallGame extends Frame {
Image sun = Toolkit.getDefaultToolkit().getImage("images/sun.jpg"); //这种写法并不好,但是是最简单的!
public void paint(Graphics g){ g.drawImage(sun, 100, 100, null); }
void launchFrame(){ setSize(500, 300); setLocation(50, 50); setTitle("尚学堂---张三作品"); setBackground(Color.black); setVisible(true); }
public static void main(String[] args){ System.out.println("我是尚学堂的高淇!"); new BallGame().launchFrame(); } } |
注意:运行时,第一次打开窗口看不到图片。需要将窗口最小化再打开即可看到! |
import java.awt.*;
public class BallGame extends Frame {
Image sun = Toolkit.getDefaultToolkit().getImage("images/sun.jpg"); //这种写法并不好,但是是最简单的!
public void paint(Graphics g){ g.drawImage(sun, 100, 100, null); g.setColor(Color.blue); g.drawLine(100, 100, 200, 200); g.drawRect(50, 50, 100, 80); g.drawOval(50, 50, 100, 80); g.setColor(Color.yellow); g.drawString("游戏开始啦!!", 80, 80); }
void launchFrame(){ setSize(500, 300); setLocation(50, 50); setTitle("尚学堂---张三作品"); setBackground(Color.black); setVisible(true); }
public static void main(String[] args){ System.out.println("我是尚学堂的高淇!"); new BallGame().launchFrame(); } } |
import java.awt.*;
public class BallGame extends Frame {
Image sun = Toolkit.getDefaultToolkit().getImage("images/sun.jpg"); //这种写法并不好,但是是最简单的! int x=100; int y=100; public void paint(Graphics g){ System.out.println("窗口被画了一次!"); g.drawImage(sun, x, y, null); x = x+2; }
void launchFrame(){ setSize(500, 300); setLocation(50, 50); setTitle("尚学堂---张三作品"); setBackground(Color.black); setVisible(true); new PaintThread().start(); }
public static void main(String[] args){ System.out.println("我是尚学堂的高淇!"); new BallGame().launchFrame(); }
class PaintThread extends Thread { public void run(){ while(true){ repaint(); //重画窗口! try{ Thread.sleep(40); //40ms 1s=1000ms }catch (Exception e) { e.printStackTrace(); } } } } } |
import java.awt.*;
public class BallGame extends Frame {
Image sun = Toolkit.getDefaultToolkit().getImage("images/sun.jpg"); //这种写法并不好,但是是最简单的! double x=100; double y=100; double degree = 0; public void paint(Graphics g){ System.out.println("窗口被画了一次!"); g.drawImage(sun, (int)x,(int)y, null); x =150+ 100*Math.cos(degree); y = 150+100*Math.sin(degree); degree = degree + 0.1; }
void launchFrame(){ setSize(500, 300); setLocation(50, 50); setTitle("尚学堂---张三作品"); setBackground(Color.black); setVisible(true); new PaintThread().start(); }
public static void main(String[] args){ System.out.println("我是尚学堂的高淇!"); new BallGame().launchFrame(); }
class PaintThread extends Thread { public void run(){ while(true){ repaint(); //重画窗口! try{ Thread.sleep(40); //40ms 1s=1000ms }catch (Exception e) { e.printStackTrace(); } } } } } |
import java.awt.*;
public class BallGame extends Frame {
Image sun = Toolkit.getDefaultToolkit().getImage("images/sun.jpg"); //这种写法并不好,但是是最简单的! double x=100; double y=100; double degree = 3.14/3; public void paint(Graphics g){ System.out.println("窗口被画了一次!"); g.drawImage(sun, (int)x,(int)y, null); x = x+ 10*Math.cos(degree); y = y+10*Math.sin(degree);
if(y>300-30){ degree = - degree; } if(x>500-30){ degree = 3.14-degree; } if(x<0){ degree = 3.14-degree; } if(y<30){ degree = -degree; } }
void launchFrame(){ setSize(500, 300); setLocation(50, 50); setTitle("尚学堂---张三作品"); setBackground(Color.black); setVisible(true); new PaintThread().start(); }
public static void main(String[] args){ System.out.println("我是尚学堂的高淇!"); new BallGame().launchFrame(); }
class PaintThread extends Thread { public void run(){ while(true){ repaint(); //重画窗口! try{ Thread.sleep(40); //40ms 1s=1000ms }catch (Exception e) { e.printStackTrace(); } } } } } |
[微软用户1]暂时跟我们的游戏无关,但是一些基本的编程知识!
标签:
原文地址:http://www.cnblogs.com/imsoft/p/4340072.html