Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Cool Need Help Converting This to Applet Plz

    Hello All,

    Turning this windowed application into an applet is beyond me. I would like some help so I can learn this awesome language. The webpage load but the game does not display, below is the source code. 3 different java files in total and 1 HTML file...I did not attach the pictures.

    If I am being lazy please point to a site that can help me navigate this. :D

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    //package sidescrollertest;
    
    /**
     *
     * @author
     */
    
    import java.awt.*;
    import javax.swing.*;
    
    
    public class FrameWeb extends JApplet {
    
    	public void init() {
    
    		resize(504,390);
    	}
    
    
    
        public FrameWeb() {
    
    
    
    		Container c = getContentPane();
    
    
            JPanel jp = new JPanel();
    
    
            jp.add(new BoardWeb());
    		c.add(jp);
           jp.setSize(504,390);
           jp.setVisible(true);
            //Jf.setBackground(Color.black);  // this doesnt do anything really or not what i wanted it to
           //Jf.setLocationRelativeTo(null);
           //Jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    
    
    
        }
        /**
         * @param args the command line arguments
         */
        ///public static void main(String[] args) {
        //    new FrameWeb();
    
      // }
    
    }
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    //package sidescrollertest;
    
    /**
     *
     * @author
     */
    import java.awt.*;
    import java.awt.event.KeyEvent;
    
    import javax.swing.ImageIcon;
    
    
    
    public class DudeWeb {
    
    int x, dx, y;
    Image still;
    //constructor
    public DudeWeb(){
        ImageIcon icon = new ImageIcon("C:/Users/Name/Desktop/SideScrolling/OurHero.png");
        still = icon.getImage();
        x = 10;
        y = 152;
    }
      //move method
    public void move() {
    
        x = x + dx;
    
    }
    
    public int getx() {
        return x;
    
    }
    
    public int gety() {
        return y;
    
    }
    
    public Image getImage() {
        return still;
    
    }
    
        public void keyPressed(KeyEvent e){
    
           int  key = e.getKeyCode();
    
             if (key == KeyEvent.VK_RIGHT)
             dx = +1;
    
             if (key == KeyEvent.VK_LEFT)
             dx = -1;
     }
             //if (key != KeyEvent.VK_RIGHT);
            // dx = 0;
    
          //   if (key != KeyEvent.VK_LEFT);
           //  dx = 0;
    
    
           public void keyReleased(KeyEvent e){
    
            int key = e.getKeyCode();
    
             if (key == KeyEvent.VK_LEFT)
             dx = 0;
    
             if (key == KeyEvent.VK_RIGHT)
             dx = 0;
        }
    
    
    
    }

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    //package sidescrollertest;
    
    
    
    
    /**
     *
     * @author
     */
    import java.awt.*;
    import java.awt.event.*;
    //import java.awt.event.ActionListener;
    //import java.awt.event.KeyAdapter;
    //import java.awt.event.KeyEvent;
    
    
    
    
    import javax.swing.*;
    
    public class BoardWeb extends JPanel implements ActionListener {
    
    DudeWeb p;
    public Image img;
    Timer time;
    
    
        //create constructor
        public BoardWeb() {
            p = new DudeWeb();
            addKeyListener(new AL());
            setFocusable(true);
            ImageIcon i = new ImageIcon("C:/Users/Name/Desktop/SideScrolling/Nebula.jpg");
            img = i.getImage();
            time = new Timer(5, this);
            time.start();
    
    
        }
    
       // public void ActionPerformed(ActionEvent e) {
         // p.move();
          // repaint();
    
      //}
    
        public void paint(Graphics g) {
            super.paint(g);
            Graphics2D g2d = (Graphics2D) g;
    
    
            g2d.drawImage(img, 0, 0, null);
            g2d.drawImage(p.getImage(), p.getx(), p.gety(), null);
    
    
    
        }
    
        public void actionPerformed(ActionEvent e) {
    if (!(p.getx() >= 404 && p.dx == 1) && !(p.getx() <= 1 && p.dx == -1))
            p.move();
            repaint();
    
                 }
    
    
    
    
    
    
        private class AL extends KeyAdapter {
            public void keyReleased(KeyEvent e){
                p.keyReleased(e);
            }
    
    
         public void keyPressed(KeyEvent e){
                p.keyPressed(e);
    
          }
       }
    }

    XML Code:
    <html>
    <head><title>The Horror of Space</title></head>
    <body bgcolor="#C0C0C0">
    <h1>The Universe Next Door</h1>
    
    <hr>
    <center>
       <applet code="FrameWeb.class" >
               
        </applet>
    
        </applet>
    </center>
    <hr>
    
    </body>
    </html>

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Default

    Hi Fubarable,

    Do you have any other links I have already read the first half of this Oracle tut. Thanks for the help though.

Similar Threads

  1. Converting java to applet...?
    By xtrapx in forum Java Applets
    Replies: 1
    Last Post: 10-16-2010, 06:38 PM
  2. Converting this Applet to an Application
    By karthus in forum New To Java
    Replies: 4
    Last Post: 07-07-2010, 05:30 AM
  3. Converting java application to applet
    By rcj66 in forum Java Applets
    Replies: 2
    Last Post: 03-16-2010, 08:41 PM
  4. Converting an App to Applet
    By josephdcoleman in forum New To Java
    Replies: 1
    Last Post: 02-21-2009, 08:07 AM
  5. Converting netbeans app to applet
    By paulious in forum New To Java
    Replies: 3
    Last Post: 10-23-2008, 12:25 PM

Tags for this Thread

Posting Permissions

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