I have successful compiled and ran the following code but the applet windows shows nothing except blank space,what could be the problem?
Im Not trying to create an applet here im trying to create a Jframe program
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//<applet code="calc.class" width=400 height=200></applet>
public class calc extends JFrame implements ActionListener {
JFrame f1;
JPanel p1 = new JPanel();
JLabel l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15,
l16, l17, l18, l19, l20, l21, l22, l23, l24;
JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
b16;
JTextField t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11;
public void init() {
f1 = new JFrame("Administrator");
p1.setLayout(new GridLayout(3, 2));
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(b1);
p1.add(b2);
f1.add(p1);
f1.setSize(300, 300);
f1.setVisible(true);
}
public void actionPerformed(ActionEvent AE) {
}
public void main(String[] args) {
calc s = new calc();
s.init();
}
}
In the CMD Window i get the following exception
java.lang.ClassCastException: calc cannot be cast to java.applet.Applet
at sun.applet.AppletPanel.createApplet(AppletPanel.java:795)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:724)
at sun.applet.AppletPanel.run(AppletPanel.java:378)
at java.lang.Thread.run(Thread.java:722)
EDIT
As per your comments i have added a Main class and changed the file name to cool.java,still its not working
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//<applet code="calc.class" width=400 height=200></applet>
public class calc extends JFrame implements ActionListener
{
JFrame f1;
JPanel p1=new JPanel();
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15,l16,l17,l18,l19,l20,l21,l22,l23,l24;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
public void init()
{
f1=new JFrame("Administrator");
p1.setLayout(new GridLayout(3,2));
p1.add(l1);p1.add(t1);p1.add(l2);
p1.add(b1);p1.add(b2);
f1.add(p1);
f1.setSize(300,300);
f1.setVisible(true);
}
public void actionPerformed(ActionEvent AE)
{
}
}
public class cool
{
public static void main(String[]args)
{
calc s=new calc();
s.init();
}
}