这是代码:
aa 级
package com.MahBonnets.Game;
import javax.swing.*;
public class aa {
public static ab f = new ab();
public static int width = 600;
public static int height = 400;
public static void main(String args[]) {
f.setSize(width, height);
f.setResizable(false);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setTitle("MAH BONNETS IS GONE");
f.setLocationRelativeTo(null);
System.out.println("Running!!");
}
}
抗体
package com.MahBonnets.Game;
import java.awt.GridLayout;
import javax.swing.*;
public class ab extends JFrame {
public ac panel;
public ab() {
panel = new ac(this);
setLayout(new GridLayout (1, 1, 0, 0));
add(panel);
}
}
和交流
package com.MahBonnets.Game;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.*;
public class ac extends JPanel implements Runnable {
public Rectangle floor;
public int floorheight = 80;
public int fps = 1000;
public boolean objectDefine = false;
public Thread game;
public ac(ab f) {
setBackground(Color.black);
defineObjects();
game = new Thread(this);
game.start(); }
void defineObjects() {
floor = new Rectangle(-10, aa.height-floorheight, aa.width+10, floorheight);
objectDefine = true;
repaint();
}
public void paint(Graphics g) {
super.paint(g);
if(objectDefine) {
g.setColor(Color.RED);
g.fillRect(floor.x, floor.y, floor.width, floor.height);
}
}
public void fpsSetter() {
try{
Thread.sleep(fps/1000);
}catch(Exception e) {
e.printStackTrace();
}
}
@Override
public void run(){
// TODO Auto-generated method stub
}
}
没有发生而应该发生的是应该在 JFrame 的底部出现一个红色矩形。我对编程完全陌生,但是我查看了与矩形有关的代码部分,一切看起来都井井有条……至少……据我所知。
如果您有任何想法,请帮帮我。谢谢。
这是我一直关注的 youtube 教程http://www.youtube.com/watch?v=0lfhcKAIr-8