Making a JApplet into a JFrame into a .jar
I have a problem making my things into a jar file as a JApplet, Think you guys could help me? (This is just the menu to my game{still under way}... it is the same format basically)... but how could you make all of this work in a .jar file?
I do know that it needs the main, and i use eclipse.
CODE BELOW
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class MenuTesting extends JApplet implements Runnable, KeyListener, MouseListener, MouseMotionListener
{
//I KNOW U NEED THIS BUT DONT KNOW WHAT TO DO
public static void main(String[] args)
{
JFrame fr=new JFrame(); //Puttign the JApplet into a Frame
fr.setBounds(0,0,1015,600);
/*JApplet menu=new MenuTesting();
fr.add(menu);*/ // DOESNT WORK
fr.setVisible(true);
}
//Threads
Thread main, thisThread;
//Graphic Variables
Dimension offDimension;
Image offImage;
Graphics offGraphics;
Font f1;
//KeyListener
int code;
String lastkey="M";
//Animations
MediaTracker tracker;
//TESTING
Image[] menu;
int mouseX=0, mouseY=0;
boolean edit=false;
JFrame frame;
public void init()
{
//Add-Ins
addKeyListener(this);
addMouseListener(this);
addMouseMotionListener(this);
tracker=new MediaTracker(this);
f1 = new Font("SansSerif", Font.BOLD, 12);
//TESTING
menu = new Image[3];
for (int i = 0 ; i <= 2 ; i++)
{
menu[i] = getImage(getCodeBase(), "Title" + i + ".gif");
tracker.addImage(menu[i], 0);
}
frame=new JFrame("Identification");
frame.addKeyListener(this);
frame.addMouseListener(this);
frame.addMouseMotionListener(this);
frame.setBounds(300,300,500,200);
//TESTING END
//Set Screen/Variables
resize(1015,600);
}
public void start()
{
main=new Thread(this);
main.start();
}
public void stop(){}
public void run()
{
thisThread=Thread.currentThread();
while(main==thisThread)
{
if (edit==true)
{
frame.setVisible(true);
if (frame.EXIT_ON_CLOSE==3)
{
edit=false;
}
}
try{
repaint();
thisThread.sleep(0);
}catch(InterruptedException e){}
}
}
//Key Events
public void keyTyped(KeyEvent t) {}
public void keyPressed(KeyEvent p)
{
code = p.getKeyCode();
lastkey = KeyEvent.getKeyText(code);
}
public void keyReleased(KeyEvent r)
{
code = r.getKeyCode();
lastkey = KeyEvent.getKeyText(code);
}
//Mouse Events
public void mouseClicked(MouseEvent e) {
//System.out.println(mouseX+" and "+mouseY);
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e)
{
if ((mouseX>100)&&(mouseX<400)&&(mouseY>420)&&(mouseY <570))
{
edit=true;
}
}
public void mouseDragged(MouseEvent arg0) {}
public void mouseMoved(MouseEvent e)
{
mouseX=e.getX();
mouseY=e.getY();
}
//Graphics
public void paint(Graphics g)
{
update(g);
}
public void update (Graphics g)
{
Dimension d = size();
// Create the offscreen graphics context
if ((offGraphics == null) || (d.width != offDimension.width)|| (d.height != offDimension.height))
{
offDimension = d;
offImage = createImage(d.width, d.height);
offGraphics = offImage.getGraphics();
}
// Erase the previous image
offGraphics.setColor(getBackground());
offGraphics.fillRect(0, 0, d.width, d.height);
offGraphics.setColor(Color.black);
//Draw Images
if (tracker.statusID(0, true) == MediaTracker.COMPLETE)
{
drawMenu(offGraphics);
}
//Save Images offScreen
g.drawImage(offImage, 0, 0, null);
try{
thisThread.sleep(0);
}catch(InterruptedException e){}
}
public void drawMenu(Graphics g)
{
g.drawImage(menu[0],0,0,this);
if (edit==false)
{
if ((mouseX>100)&&(mouseX<400)&&(mouseY>420)&&(mouseY <570))
{
g.drawImage(menu[2],0,385,this);
}
else
{
g.drawImage(menu[1],0,385,this);
}
}
else
{
g.drawImage(menu[2],0,385,this);
}
}
}