Results 1 to 4 of 4
  1. #1
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default uploading applet with multiple classes help

    Hi ive just created my first applet which uses two classes, however when uploading both classes i realised that in the HTML code i could only refer to one class,

    XML Code:
    <APPLET codebase="." code="mainjapplet.class" width=200 height=300></APPLET>
    so i refered to the class which extends JApplet ("mainjapplet.class") hoping that somehow it was smart enough to reconise the other class "test.class" in the same directory (which extends JPanel and has all the contents).

    However when i checked the URL primecode.co.uk, the applet crashes before it loads.

    Im not sure what the problem is here. Ive uploaded a simple hello world applet before which painted a string, and that worked.


    Heres my code for both my classes below. Also please note that i havent put them in a package, i dont know if this is compulsary. The reason why i didnt put them in package it because when i typed in package test; at the top of both classes, it gave me an error saying incorrect package even though the classes are in a folder called test.

    the class which i refer to, which extends JApplet

    PHP Code:
    //package test;
    
    import javax.swing.*;
    import java.awt.*;
    
    public class mainjapplet extends JApplet {
    
        test mypanel;
    
        @Override public void init(){
          
             mypanel = new test();
             mypanel.setBackground(Color.orange);
    
             getContentPane().add(mypanel);
    
        }
    
    }

    the class which is refered to by the above class, which extends JFrame and which contains the graphics and object.

    PHP Code:
    //package test;
    
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    
    public class test extends JPanel {
    
        int d = 10;
        JSlider slider;
        BorderLayout bl = new BorderLayout();
    
        public test(){
    
             this.setLayout(bl);
             slider = new JSlider(SwingConstants.HORIZONTAL,0,200,10); //create slider
             slider.setMajorTickSpacing(10);  //10 pixels spacing for ticks
             slider.setPaintTicks(true);      //show ticks
             this.add(BorderLayout.SOUTH,slider);
             action();
    
        }
    
        @Override public void paintComponent(Graphics g){
    
            super.paintComponent(g);
            g.fillOval(15, 15, d, d);
        }
    
        public void setD(int newD){
    
            d = (newD >= 0 ? newD: 10);
            repaint();
            
        }
    
        @Override public Dimension getPreferredSize(){
            return new Dimension(200,200);
        }
    
        public Dimension getMinimiumSize(){
            return getPreferredSize();
        }
    
        public void action(){
    
            slider.addChangeListener(new ChangeListener(){public void stateChanged(ChangeEvent e){
    
                setD(slider.getValue());
                
            }});
    
        }
    
    
    
    }


    both files are uploaded the root directory of my URL.
    Last edited by alacn; 07-26-2010 at 01:10 AM.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    Was there an error message in the browser's java console?
    Please copy and paste it here.

    Meanwhile you could try this:
    Take the codebase= attribute out of the <APPLET tag. If both your class files are together, the browser will ask for the next class file it needs to come from the same folder it got the first one from.
    Also remove the .class from the code= attribute. Some browsers think that the name.class format is a package with name the package and class.class (it adds the extra .class) being the name of the class file.

  3. #3
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    i tried what you said norm and it still freezes. I dont get any errors, it just freezes.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  4. #4
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default

    got it to work

    PHP Code:
    <html>
    <body>
    <applet code = 'mainjapplet.class' 
        archive = 'test.jar', 
        width = 300, 
        height = 300 />
    
    </body>
    </html>
    Teaching myself java so that i can eventually join the industry! Started in June 2010

Similar Threads

  1. Help with multiple frames/classes
    By Celletti in forum AWT / Swing
    Replies: 1
    Last Post: 04-28-2010, 03:18 AM
  2. Uploading in an ftp applet help
    By d4dirty in forum Java Applets
    Replies: 0
    Last Post: 01-07-2010, 09:24 AM
  3. Java Applet + File Uploading
    By Moncleared in forum New To Java
    Replies: 4
    Last Post: 02-02-2009, 06:33 PM
  4. Multiple class applet
    By lordbob75 in forum Java Applets
    Replies: 5
    Last Post: 01-08-2009, 01:22 AM
  5. How to use multiple timer classes in swings
    By theone3nu in forum AWT / Swing
    Replies: 12
    Last Post: 12-30-2008, 02:30 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
  •