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,
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
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.
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.