当我尝试运行我的代码时,Eclipse抱怨我的代码没有主要方法。我只是在Github上复制了一个.zip文件,用于编码类。有人可以告诉我这是什么问题吗?我已经问过我的老师,但他已经花了很长时间才回答。这是我的代码(它有点长,因为我不知道什么不包括:):
bb.view.arena;
import bb.model.GameModel;
import bb.view.SpriteFactory;
import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import static bb.BBConfig.*;
/**
* Created by willie on 6/4/17.
*/
public class ArenaPane extends JComponent {
private GameModel gameModel;
private SpriteFactory spriteFactory;
public ArenaPane(GameModel gameModel, SpriteFactory spriteFactory) {
this.gameModel = gameModel;
this.spriteFactory = spriteFactory;
}
@Override
public Dimension getPreferredSize() {
return ARENA_PANE_SIZE_PX;
}
@Override
public void paint(Graphics g) {
g.translate(ARENA_MARGIN_LEFT_RIGHT_PX, 0);
doPaintBorder(g);
g.translate(ARENA_BORDER_SIZE_PX, ARENA_BORDER_SIZE_PX);
g.setClip(0, 0, ARENA_INNER_WIDTH_PX, ARENA_INNER_HEIGHT_PX);
paintPlayer(g);
g.translate(-ARENA_BORDER_SIZE_PX, -ARENA_BORDER_SIZE_PX);
g.translate(-ARENA_MARGIN_LEFT_RIGHT_PX, 0);
}
private void doPaintBorder(Graphics g) {
g.setColor(Color.YELLOW);
g.fillRect(0, 0, ARENA_OUTER_WIDTH_PX, ARENA_OUTER_HEIGHT_PX);
g.setColor(Color.BLACK);
g.fillRect(ARENA_BORDER_SIZE_PX, ARENA_BORDER_SIZE_PX, ARENA_INNER_WIDTH_PX, ARENA_INNER_HEIGHT_PX);
}
private void paintPlayer(Graphics g) {
// Note: Arena dimensions are 292 x 230.
// drawImage() starts from the sprite's top-left corner.
BufferedImage lexi = spriteFactory.getLexi();
g.drawImage(lexi, 100, 100, 16, 16, null);
// Step 1. Get the sprite from the sprite factory
// TODO
// Step 2. Draw the sprite on the screen
// g.drawImage(image, x, y, width, height, null);
// TODO
}
}
谢谢, Svadrut
答案 0 :(得分:0)
你有一个java Swing applet,它可以在任何安装了相应Java Plug-in版本的浏览器中运行,并且有两个选项可以运行它 -
<html>
<body>
<applet code="ArenaPane.class" width="300" height="300">
</applet>
</body>
</html>
/*
<applet code="ArenaPane.class" width="300" height="300">
</applet>
*/
要通过appletviewer工具执行applet,请在命令提示符下写入:
> c:\>javac ArenaPane.java
> c:\>appletviewer ArenaPane.java