Results 1 to 3 of 3
  1. #1
    aqualicy is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default 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);
    }
    }




    }

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    I recommend reading this Eclipse and JAR

    Report that helped
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    1) Cross posted

    2) Code formatting tags not used.

    It would be nice if you learned how to use the forum properly by posting readable code and not cross posting your question.

Similar Threads

  1. JApplet on MAC
    By ld_pvl in forum Java Applets
    Replies: 0
    Last Post: 08-23-2009, 01:40 PM
  2. JApplet.getGraphics() draws but JFrame doesn't
    By ChazZeromus in forum New To Java
    Replies: 5
    Last Post: 07-27-2009, 10:02 PM
  3. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  4. JFrame to JApplet or JApplet to JApplet
    By ramesh.8189 in forum AWT / Swing
    Replies: 13
    Last Post: 02-08-2009, 06:14 AM
  5. help with converting to JApplet
    By Simmy in forum AWT / Swing
    Replies: 2
    Last Post: 08-09-2007, 08:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •