[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

Running an applet in html

I am trying to run an applet in html, but when it goes to my browser it does not show up: Here is the code;


<HTML>
<APPLET CODE = "celluar.class"WIDTH =450 HEIGHT = 200>
</APPLET>
</HTML>

Open in new window

0
bdiddy05
Asked:
bdiddy05
  • 7
  • 4
  • 4
2 Solutions
 
CEHJCommented:
You're missing a space. You should quote the attributes too
0
 
objectsCommented:
try this:

<APPLET CODE = "cellular.class" WIDTH=450 HEIGHT=200>

and make sure the class file is in the same directory as the html

0
 
bdiddy05Author Commented:
Hey guys,

First thank you both for the help before.

I tried both an it is still not working.

My class file and html file are both on my local c under a java file.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
check the java console it should show the problem

0
 
CEHJCommented:
Have a look at the applet console via the java Control Panel
0
 
objectsCommented:
try this:L

<APPLET CODE = "celluar.class" WIDTH=450 HEIGHT=200>


If you are using the code you posted in your other question then all you will get is a blank page as its not an applet.
only applet can be displayed on browser page

0
 
objectsCommented:
try changing your source to

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
 
 
public class celluar extends JApplet implements ActionListener{
    // creates borders for display
 
    JTextField number = new JTextField();

//    public static void main(String[] args) {
//        celluar c = new celluar();
//    }
    public void init() {
 
        //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(4, 3));
 
        panel.setBackground(Color.GRAY);
 
        // creates and add buttons for keypad
 
        JButton b1 = new JButton("1");
        panel.add(b1);
        b1.addActionListener(this);
        b1.setActionCommand("1");
        b1.setBackground(Color.BLUE);
 
        JButton b2 = new JButton("2");
        panel.add(b2);
        b2.addActionListener(this);
        b2.setActionCommand("2");
        b2.setBackground(Color.BLUE);
 
        JButton b3 = new JButton("3");
        panel.add(b3);
        b3.addActionListener(this);
        b3.setActionCommand("3");
        b3.setBackground(Color.BLUE);
 
        JButton b4 = new JButton("4");
        panel.add(b4);
        b4.addActionListener(this);
        b4.setActionCommand("4");
        b4.setBackground(Color.BLUE);
 
        JButton b5 = new JButton("5");
        panel.add(b5);
        b5.addActionListener(this);
        b5.setActionCommand("5");
        b5.setBackground(Color.BLUE);
 
        JButton b6 = new JButton("6");
        panel.add(b6);
        b6.addActionListener(this);
        b6.setActionCommand("6");
        b6.setBackground(Color.BLUE);
 
        JButton b7 = new JButton("7");
        panel.add(b7);
        b7.addActionListener(this);
        b7.setActionCommand("7");
        b7.setBackground(Color.BLUE);
 
        JButton b8 = new JButton("8");
        panel.add(b8);
        b8.addActionListener(this);
        b8.setActionCommand("8");
        b8.setBackground(Color.BLUE);
 
        JButton b9 = new JButton("9");
        panel.add(b9);
        b9.addActionListener(this);
        b9.setActionCommand("9");
        b9.setBackground(Color.BLUE);
 
        JButton b10 = new JButton("*");
        panel.add(b10);
        b10.addActionListener(this);
        b10.setActionCommand("*");
        b10.setBackground(Color.BLUE);
 
        JButton b11 = new JButton("0");
        panel.add(b11);
        b11.addActionListener(this);
        b11.setActionCommand("0");
        b11.setBackground(Color.BLUE);
 
 
        JButton b12 = new JButton("#");
        panel.add(b12);
        b12.addActionListener(this);
        b12.setActionCommand("#");
        b12.setBackground(Color.BLUE);
 
 
 
 
 
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(panel,BorderLayout.CENTER);
 
        number.setColumns(15);
        getContentPane().add(number,BorderLayout.NORTH);
 
//        pack();
//        setVisible(true);
 
    }
 
    public void actionPerformed(ActionEvent e) {
          number.setText(number.getText()+e.getActionCommand());
    }
}
0
 
bdiddy05Author Commented:
when i tried the new code: I got the error message exception in thread "main" java.lang.NoSuchMethodError: main
0
 
CEHJCommented:
You commented out main. Uncomment it
0
 
objectsCommented:
> when i tried the new code: I got the error message exception in thread "main" java.lang.NoSuchMethodError: main

run it by loading the html i posted above

0
 
bdiddy05Author Commented:
Im sorry but im confused. if the class isn't working then how would the html work.
0
 
objectsCommented:
because applets and applications are different
applications need a main, applets do not

0
 
objectsCommented:
this will run as a application or applet

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
 
 
public class celluar extends JApplet implements ActionListener{
    // creates borders for display
 
    JTextField number = new JTextField();

    public static void main(String[] args) {
          JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        celluar c = new celluar();
        c.init();
        frame.getContentPane().add(c);
      frame.pack();
      frame.setVisible(true);
    }
    public void init() {
 
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(4, 3));
 
        panel.setBackground(Color.GRAY);
 
        // creates and add buttons for keypad
 
        JButton b1 = new JButton("1");
        panel.add(b1);
        b1.addActionListener(this);
        b1.setActionCommand("1");
        b1.setBackground(Color.BLUE);
 
        JButton b2 = new JButton("2");
        panel.add(b2);
        b2.addActionListener(this);
        b2.setActionCommand("2");
        b2.setBackground(Color.BLUE);
 
        JButton b3 = new JButton("3");
        panel.add(b3);
        b3.addActionListener(this);
        b3.setActionCommand("3");
        b3.setBackground(Color.BLUE);
 
        JButton b4 = new JButton("4");
        panel.add(b4);
        b4.addActionListener(this);
        b4.setActionCommand("4");
        b4.setBackground(Color.BLUE);
 
        JButton b5 = new JButton("5");
        panel.add(b5);
        b5.addActionListener(this);
        b5.setActionCommand("5");
        b5.setBackground(Color.BLUE);
 
        JButton b6 = new JButton("6");
        panel.add(b6);
        b6.addActionListener(this);
        b6.setActionCommand("6");
        b6.setBackground(Color.BLUE);
 
        JButton b7 = new JButton("7");
        panel.add(b7);
        b7.addActionListener(this);
        b7.setActionCommand("7");
        b7.setBackground(Color.BLUE);
 
        JButton b8 = new JButton("8");
        panel.add(b8);
        b8.addActionListener(this);
        b8.setActionCommand("8");
        b8.setBackground(Color.BLUE);
 
        JButton b9 = new JButton("9");
        panel.add(b9);
        b9.addActionListener(this);
        b9.setActionCommand("9");
        b9.setBackground(Color.BLUE);
 
        JButton b10 = new JButton("*");
        panel.add(b10);
        b10.addActionListener(this);
        b10.setActionCommand("*");
        b10.setBackground(Color.BLUE);
 
        JButton b11 = new JButton("0");
        panel.add(b11);
        b11.addActionListener(this);
        b11.setActionCommand("0");
        b11.setBackground(Color.BLUE);
 
 
        JButton b12 = new JButton("#");
        panel.add(b12);
        b12.addActionListener(this);
        b12.setActionCommand("#");
        b12.setBackground(Color.BLUE);
 
 
 
 
 
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(panel,BorderLayout.CENTER);
 
        number.setColumns(15);
        getContentPane().add(number,BorderLayout.NORTH);
 
 
    }
 
    public void actionPerformed(ActionEvent e) {
          number.setText(number.getText()+e.getActionCommand());
    }
}
0
 
bdiddy05Author Commented:
It worked, using Object's updated code and CEHJ's suggestion about the space. Thank you both.
0
 
CEHJCommented:
:-)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 7
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now