我最近开始为java4k游戏大赛制作一个Java applet游戏,但我是个小应用程序新手,我对它们有一些疑问。
我有一个用eclipse编写的applet,我可以使用applet查看器在eclipse中运行它,但是我如何编译它呢?似乎没有编译applet的选项。
..and什么是jar归档?
谢谢。
这也是我的资源,以防你需要它:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.imageio.ImageIO;
public class game extends Applet implements KeyListener{
private static final long serialVersionUID = 1L;
public int x = 50,y = 50;
public boolean right, left, down, up, lt = false, rt = true;
public Image buffer;
BufferedImage img = null;
BufferedImage imgl = null;
Graphics bg;
public void init(){
try {
img = ImageIO.read(new File("C:/player.png"));
} catch (IOException e){}
try {
imgl = ImageIO.read(new File("C:/playerl.png"));
} catch (IOException e){}
addKeyListener(this);
setSize(400,200);
setBackground(Color.cyan);
Timer t = new Timer();
t.schedule(new TimerTask(){public void run(){
if (right == true){x++;}
if (left == true){x--;}
if (up == true){y--;}
if (down == true){y++;}
repaint();
}},10,10);
buffer = createImage(400,200);
bg = buffer.getGraphics();
}
public void paint(Graphics g){
bg.setColor(Color.WHITE);
//bg.clearRect(0, 0, 400, 200);
if (rt == true){
bg.drawImage(img,x,y, this);
}
if (lt == true){
bg.drawImage(imgl,x,y, this);
}
g.drawImage(buffer,0,0,this);
}
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e){
if (e.getKeyCode() == 37){
left = true;
lt = true;
rt = false;
}
if (e.getKeyCode() == 39){
right = true;
rt = true;
lt = false;
}
if (e.getKeyCode() == 38){
up = true;
}
if (e.getKeyCode() == 40){
down = true;
}
}
public void keyReleased(KeyEvent e){
if (e.getKeyCode() == 37){
left = false;
}
if (e.getKeyCode() == 39){
right = false;
}
if (e.getKeyCode() == 38){
up = false;
}
if (e.getKeyCode() == 40){
down = false;
}
}
public void update(Graphics g){
paint(g);
}
}
发布于 2011-12-03 05:06:09
您将需要导出为JAR文件。为此,您需要右键单击项目>导出。
选择Java > JAR文件
在JAR Export对话框中,为您的项目选择您想要导出的部件(Export generated class files and resources)。可能还想指定输出文件夹。其余的选项可以保留为默认值,然后转到Finish。
您可以在applet查看器中运行JAR,也可以从网页中的APPLET标签中运行jar,请确保设置archive="jar文件名“。
发布于 2011-12-03 05:04:03
在Eclipse中,右键单击项目,单击export,然后导出为jar。
然后,您可以将此jar嵌入到您的网页中,以作为applet运行,或者在外部通过appletviewer运行。
Jar和Archive JAR之间没有区别。JAR代表"Java ARchive“。
发布于 2014-07-17 20:08:21
如果没有main方法,就不能创建自执行jar。幸运的是,这样做非常简单。
您可以在主类中创建名为public static void main(String[] args)
的方法。然后做一些像这样的事情:
yourmainclassname yourname = new yourmainclassname(); //create new object
yourname.init(); //invoke the applet's init() method
yourname.start(); //starts the applet
// Create a window (JFrame) and make applet the content pane.
JFrame window = new JFrame("Put something here");
window.setSize(640, 480); //size in pixels
window.setContentPane(theApplet); //
window.setVisible(true);
window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
就这样。接下来,您可以只将项目导出到self executive。
https://stackoverflow.com/questions/8362573
复制相似问题