在我的;“齿轮”;节目,为什么黑圈(森林)一直在嗡嗡作响? import javax.swing.*; 导入java.awt.*; 导入java.awt.event.*; 导入java.util.Random; //我是一个非常粗鲁的程序员 公共类Gear
在我的;“齿轮”;节目,为什么黑圈(森林)一直在嗡嗡作响?在我的;“齿轮”;节目,为什么黑圈(森林)一直在嗡嗡作响? import javax.swing.*; 导入java.awt.*; 导入java.awt.event.*; 导入java.util.Random; //我是一个非常粗鲁的程序员 公共类Gear,java,swing,Java,Swing,在我的;“齿轮”;节目,为什么黑圈(森林)一直在嗡嗡作响? import javax.swing.*; 导入java.awt.*; 导入java.awt.event.*; 导入java.util.Random; //我是一个非常粗鲁的程序员 公共类Gears扩展JFrame实现ActionListener、KeyListener{ 静态布尔芽; 静态int水=500; 静态JLabel-waterLabel=新JLabel(“水:“+water+”G”); 静态int-fx2; 二○○二财政年度
import javax.swing.*;
导入java.awt.*;
导入java.awt.event.*;
导入java.util.Random;
//我是一个非常粗鲁的程序员
公共类Gears扩展JFrame实现ActionListener、KeyListener{
静态布尔芽;
静态int水=500;
静态JLabel-waterLabel=新JLabel(“水:“+water+”G”);
静态int-fx2;
二○○二财政年度;
公共静态int燃料=999;
静态随机r=新随机();
静态BorderLayout bor=新的BorderLayout();
JButton craft=新JButton(“craft”);
静态整数平衡=0;
静态JLabel balanceLabel=新JLabel(“$:”+余额);
公共齿轮()
{
超级(“齿轮”);
添加(waterLabel,BorderLayout.WEST);
设置布局(bor);
设置大小(10001000);
添加(balanceLabel,BorderLayout.EAST);
this.getContentPane().add(新的BasicCity(),BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(真);
addKeyListener(此);
设置聚焦(真);
setFocusTraversalKeysEnabled(false);
}
公共静态void main(字符串[]args){
齿轮g=新齿轮();
}
已执行的公共无效操作(操作事件e){
}
按下公共无效键(按键事件e){
如果(例如getKeyChar()=='q')
{
射击=真;
重新油漆();
}
如果(e.getKeyChar()=='w')
{
基本度y=基本度y-5;
BasicCity.ny=BasicCity.ny-5;
重新油漆();
}
如果(例如getKeyChar()=='a')
{
基本性x=基本性x-5;
BasicCity.nx=BasicCity.nx-5;
重新油漆();
}
如果(例如getKeyChar()=='d')
{
基本度x=基本度x+5;
BasicCity.nx=BasicCity.nx+5;
重新油漆();
}
如果(如getKeyChar()=='s')
{
基本度y=基本度y+5;
BasicCity.ny=BasicCity.ny+5;
重新油漆();
}
如果(e.getKeyChar()=='W')
{
基本度y=基本度y-5;
BasicCity.ny=BasicCity.ny-5;
重新油漆();
}
如果(例如getKeyChar()=='A')
{
基本性x=基本性x-5;
BasicCity.nx=BasicCity.nx-5;
重新油漆();
}
如果(例如getKeyChar()=='D')
{
如果(燃油!=0==true&&fuel>0==true)
{
基本度x=基本度x+5;
BasicCity.nx=BasicCity.nx+5;
重新油漆();
}
如果(如getKeyChar()=='S')
{
如果(燃油!=0==true&&fuel>0==true)
{
基本度y=基本度y+5;
BasicCity.ny=BasicCity.ny+5;
重新油漆();
}
}
}
}
公共无效密钥已释放(密钥事件e){
//
}
public void keyTyped(KeyEvent e){
//TODO自动生成的方法存根
}
}
类基本性扩展了JComponent{
公共静态int x=200;
公共静态int y=200;
公共静态int nx=217;
公共静态int ny=310;
静态int fx=齿轮。r.nextInt(500)+1;
静态int fy=齿轮。r.nextInt(500)+1;
公共组件(图形g){
g、 Fillova(外汇,财政年度,100100);
如果(fx+2y)
{
Gears.fuel=Gears.fuel+100;
fx=齿轮。r.nextInt(200)+1;
fy=齿轮。r.nextInt(200)+1;
如果(fx+10y)
{
Gears.fuel=Gears.fuel+100;
fx=齿轮。r.nextInt(200)+1;
fy=齿轮。r.nextInt(200)+1;
如果(fx+10y)
{
Gears.fuel=Gears.fuel+100;
fx=齿轮。r.nextInt(200)+1;
fy=齿轮。r.nextInt(200)+1;
如果(fx+10import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
// I am a very noobish programmer
public class Gears extends JFrame implements ActionListener, KeyListener{
static boolean shoot;
static int water = 500;
static JLabel waterLabel = new JLabel("water: " + water + "G");
static int fx2;
static int fy2;
public static int fuel = 999;
static Random r = new Random();
static BorderLayout bor = new BorderLayout();
JButton craft = new JButton("Craft");
static int balance = 0;
static JLabel balanceLabel = new JLabel("$: " + balance);
public Gears()
{
super("Gears");
add(waterLabel, BorderLayout.WEST);
setLayout(bor);
setSize(1000,1000);
add(balanceLabel, BorderLayout.EAST);
this.getContentPane().add(new BasicCity(), BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
addKeyListener(this);
setFocusable(true);
setFocusTraversalKeysEnabled(false);
}
public static void main(String[] args) {
Gears g = new Gears();
}
public void actionPerformed(ActionEvent e) {
}
public void keyPressed(KeyEvent e) {
if(e.getKeyChar() == 'q')
{
shoot = true;
repaint();
}
if(e.getKeyChar() == 'w')
{
BasicCity.y = BasicCity.y - 5;
BasicCity.ny = BasicCity.ny - 5;
repaint();
}
if(e.getKeyChar() == 'a')
{
BasicCity.x = BasicCity.x - 5;
BasicCity.nx = BasicCity.nx - 5;
repaint();
}
if(e.getKeyChar() == 'd')
{
BasicCity.x = BasicCity.x + 5;
BasicCity.nx = BasicCity.nx + 5;
repaint();
}
if(e.getKeyChar() == 's')
{
BasicCity.y = BasicCity.y + 5;
BasicCity.ny = BasicCity.ny + 5;
repaint();
}
if(e.getKeyChar() == 'W')
{
BasicCity.y = BasicCity.y - 5;
BasicCity.ny = BasicCity.ny - 5;
repaint();
}
if(e.getKeyChar() == 'A')
{
BasicCity.x = BasicCity.x - 5;
BasicCity.nx = BasicCity.nx - 5;
repaint();
}
if(e.getKeyChar() == 'D')
{
if(fuel != 0 == true && fuel > 0 == true)
{
BasicCity.x = BasicCity.x + 5;
BasicCity.nx = BasicCity.nx + 5;
repaint();
}
if(e.getKeyChar() == 'S')
{
if(fuel != 0 == true && fuel > 0 == true)
{
BasicCity.y = BasicCity.y + 5;
BasicCity.ny = BasicCity.ny + 5;
repaint();
}
}
}
}
public void keyReleased(KeyEvent e) {
//
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
}
class BasicCity extends JComponent{
public static int x = 200;
public static int y = 200;
public static int nx = 217;
public static int ny = 310;
static int fx = Gears.r.nextInt(500) + 1;
static int fy = Gears.r.nextInt(500) + 1;
public void paintComponent(Graphics g) {
g.fillOval(fx,fy,100,100);
if(fx + 2 < x)
{
if(fy + 2 > y)
{
Gears.fuel = Gears.fuel + 100;
fx = Gears.r.nextInt(200) + 1;
fy = Gears.r.nextInt(200) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
}
}
}
g.fillOval(fx, fy, 100,100);
Gears.balance = Gears.balance + 100;
Gears.balanceLabel.setText("$: " + Gears.balance);
repaint();
}
}
if(fx - 2 < x)
{
if(fy - 2 > y)
{
Gears.fuel = Gears.fuel + 100;
fx = Gears.r.nextInt(200) + 1;
fy = Gears.r.nextInt(200) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
}
}
}
g.fillOval(fx, fy, 100,100);
Gears.balance = Gears.balance + 100;
Gears.balanceLabel.setText("$: " + Gears.balance);
repaint();
}
}
if(fx - 2 < x)
{
if(fy - 2 > y)
{
Gears.fuel = Gears.fuel + 100;
fx = Gears.r.nextInt(200) + 1;
fy = Gears.r.nextInt(200) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
}
}
}
g.fillOval(fx, fy, 100,100);
repaint();
}
}
if(fx + 2 < x)
{
if(fy + 2 > y)
{
Gears.fuel = Gears.fuel + 100;
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
if(fx + 10 < x == true || fx - 10 < x == true)
{
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
}
}
}
fx = Gears.r.nextInt(500) + 1;
fy = Gears.r.nextInt(500) + 1;
g.fillOval(fx, fy, 100,100);
repaint();
}
}
g.drawRect(x,y,100,100);
g.setColor(Color.DARK_GRAY);
g.setColor(Color.DARK_GRAY);
g.drawString("Roamcraft", nx, ny);
g.setColor(Color.WHITE);
}
}