When you compile and get something like this in the console
C:\jexp>javac shooterrx.java
Note: shooterrx.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
you can do this to find out what is deprecated
C:\jexp>javac -Xlint:deprecation shooterrx.java
shooterrx.java:27: warning: [deprecation] resize(int,int) in java.awt.Component
has been deprecated
f.resize(900, 900);
^
1 warning
and then look up the method in the indicated api to find what to replace it with.
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.event.MouseInputAdapter;
public class ShooterRx extends Canvas
{
Image ground;
Image ship;
Thread t;
public Ship s = new Ship();
public static int score = 0;
public static int level = 1;
public long gameTime;
public long numNums;
public boolean cached = false;
public ShooterRx()
{
ship = loadImage("Ship.bmp");
//"images/dukeWaveRed.gif");
ground = loadImage("ground.bmp");
Cursor c = Toolkit.getDefaultToolkit().
createCustomCursor(ship, new Point(0, 0), "cursor");
setCursor(c);
MouseHandler handler = new MouseHandler();
addMouseListener(handler);
addMouseMotionListener(handler);
}
private Image loadImage(String path)
{
Image image = Toolkit.getDefaultToolkit().createImage(path);
MediaTracker mt = new MediaTracker(this);
mt.addImage(image, 0);
try
{
mt.waitForID(0);
}
catch(InterruptedException e)
{
System.out.println("load interruption for: " + path);
}
return image;
}
public void paint(Graphics g)
{
drawScreen(g);
}
public void update(Graphics g)
{
// drawScreen(g);
paint(g);
}
public void drawScreen(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
g2d.fillRect(0,0, getWidth(), getHeight());
g2d.drawImage(ship, 200, 200, this);
int x = 0;
int y = getHeight() - ground.getHeight(this);
g2d.drawImage(ground, x, y, this);
g2d.setColor(Color.WHITE);
g2d.drawString("Score: " + score, 20, 20);
g2d.drawString("Lives: " + s.lives, 20, 30);
g2d.drawString("Level " + level, getWidth() - 60, 20);
}
public static void main(String[] args)
{
ShooterRx app = new ShooterRx();
Frame f = new Frame();
// f.setLayout(new FlowLayout());
System.out.println("Frame default layout = " +
f.getLayout().getClass().getName());
f.add(app);
f.setSize(600, 600);
f.addWindowListener(new WindowHandler());
f.setVisible(true);
}
private class MouseHandler extends MouseInputAdapter
{
public void mouseClicked(MouseEvent arg0)
{
// i want to make it where you click the mouse and,
// a bullet will come out. I have the collision detecting already.
Toolkit.getDefaultToolkit().beep();
}
public void mouseMoved(MouseEvent me)
{
// i want to make the mouse the ship.
//like every time you move your mouse the ship moves.
// Should work if you make the ship the Cursor.
}
}
}
class WindowHandler extends WindowAdapter
{
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
}
class Ship
{
public int lives = 3;
public int speed = 3;
public boolean moving = false;
public boolean fire = true;
}