| | |
Java Applet
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 31
Reputation:
Solved Threads: 1
I have a java aplpet in eclipse. How do i get my java applet to load in an html web page. I put the .class file from the bin director in the same directory as my web page. I tried applet tag but it gives me an empty white box. Here is the code for my web page.
Java Syntax (Toggle Plain Text)
<html> <body > <applet code="Main2.class" width="800" height="600"> </body> </html>
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
0
#2 Nov 10th, 2009
Looks fine to me. You need to get the error message. Does it work when you run it on a local machine? Try putting Main2.class and the html page in the same folder on your local hard drive and double-clicking on the html file to open a browser. See if it works. If not, run it through appletviewer at the command line and see what error mssage(s) you get.
http://java.sun.com/j2se/1.5.0/docs/...gs.html#applet
This link may be of some help. From it:
You might want to stick in the "Your browser does not support..." line in there. Again, everything looks fine to me, so you need to find the exact error (i.e. can't find Main2.class or something).
http://java.sun.com/j2se/1.5.0/docs/...gs.html#applet
This link may be of some help. From it:
HTML Syntax (Toggle Plain Text)
<applet code=Applet1.class width="200" height="200"> Your browser does not support the <code>applet</code> tag. </applet>
You might want to stick in the "Your browser does not support..." line in there. Again, everything looks fine to me, so you need to find the exact error (i.e. can't find Main2.class or something).
•
•
Join Date: Mar 2008
Posts: 31
Reputation:
Solved Threads: 1
0
#3 Nov 10th, 2009
I added the browser does not support line and it is still just giving me an empty white box. When I run the applet in the applet viewer it works just fine. Here is my applet code. Did I set it up incorrectly? I believe I have gotten applets to work this way before. Do I need to implement start(), stop(), or destroy() methods?
Java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; import java.applet.Applet; import javax.swing.*; public class Main3 extends JApplet { //globals for user interface private Container content; private JPanel centerPanel; //Bottom panel that changes private CardLayout card; //Layout for the applet //globals for Euclidean Algorithm private static JTextField eucl_ai; private static JTextField eucl_bi; private static JTextArea eucl_o; //This will initialize all of the GUIs, even the ones not showing public void init() { //Applet Settings content = getContentPane(); setSize(800, 600); content.setBackground(Color.GREEN); content.setLayout(new BorderLayout()); //This is the panel that contains all the buttons JPanel northPanel = new JPanel(); //Button for the Vigenere cipher JButton vigenere_b = new JButton("Vigenere Cipher"); vigenere_b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vigenere_gui(); } }); northPanel.add(vigenere_b); //Button for the Euclidean Algorithm JButton eucl_b = new JButton("Euclidean"); eucl_b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { eucl_gui(); } }); northPanel.add(eucl_b); //Button for Reset JButton reset_b = new JButton("Reset"); reset_b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { reset_gui(); } }); northPanel.add(reset_b); //Add the north panel to the applet content.add(northPanel, BorderLayout.NORTH); //Set the layout in the applet to cardlayout centerPanel = new JPanel(); card = new CardLayout(); centerPanel.setLayout(card); //Set the gui for the Euclidean Algorithm JPanel euclPanel = new JPanel(); euclPanel.setBackground(Color.WHITE); SpringLayout eucl_layout = new SpringLayout(); euclPanel.setLayout(eucl_layout); //Text JTextField eucl_1 = new JTextField(); eucl_1.setBorder(BorderFactory.createEmptyBorder()); eucl_1.setText("Extended Euclidean Algorithm"); eucl_1.setEditable(false); eucl_1.setBackground(Color.WHITE); eucl_layout.putConstraint(SpringLayout.WEST, eucl_1, 5, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_1, 5, SpringLayout.NORTH, content); euclPanel.add(eucl_1); //Text JTextField eucl_2 = new JTextField(); eucl_2.setBorder(BorderFactory.createEmptyBorder()); eucl_2.setText("Enter a,b to find gcd(a,b)"); eucl_2.setEditable(false); eucl_2.setBackground(Color.WHITE); eucl_layout.putConstraint(SpringLayout.WEST, eucl_2, 5, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_2, 55, SpringLayout.NORTH, content); euclPanel.add(eucl_2); //Text JTextField eucl_3 = new JTextField(); eucl_3.setBorder(BorderFactory.createEmptyBorder()); eucl_3.setText("a:"); eucl_3.setEditable(false); eucl_3.setBackground(Color.WHITE); eucl_layout.putConstraint(SpringLayout.WEST, eucl_3, 5, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_3, 80, SpringLayout.NORTH, content); euclPanel.add(eucl_3); //User Input eucl_ai = new JTextField(3); eucl_ai.setBorder(BorderFactory.createLineBorder(Color.BLACK)); eucl_layout.putConstraint(SpringLayout.WEST, eucl_ai, 25, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_ai, 80, SpringLayout.NORTH, content); euclPanel.add(eucl_ai); //Text JTextField eucl_4 = new JTextField(); eucl_4.setBorder(BorderFactory.createEmptyBorder()); eucl_4.setText("b:"); eucl_4.setEditable(false); eucl_4.setBackground(Color.WHITE); eucl_layout.putConstraint(SpringLayout.WEST, eucl_4, 75, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_4, 80, SpringLayout.NORTH, content); euclPanel.add(eucl_4); //User Input eucl_bi = new JTextField(3); eucl_bi.setBorder(BorderFactory.createLineBorder(Color.BLACK)); eucl_layout.putConstraint(SpringLayout.WEST, eucl_bi, 95, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_bi, 80, SpringLayout.NORTH, content); euclPanel.add(eucl_bi); //Submit Button JButton eucl_submit = new JButton("Submit"); eucl_submit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { process_eucl(); } }); eucl_layout.putConstraint(SpringLayout.WEST, eucl_submit, 5, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_submit, 105, SpringLayout.NORTH, content); euclPanel.add(eucl_submit); //Text JTextField eucl_5 = new JTextField(); eucl_5.setBorder(BorderFactory.createEmptyBorder()); eucl_5.setText("Output:"); eucl_5.setEditable(false); eucl_5.setBackground(Color.WHITE); eucl_layout.putConstraint(SpringLayout.WEST, eucl_5, 5, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_5, 155, SpringLayout.NORTH, content); euclPanel.add(eucl_5); //Output eucl_o = new JTextArea(15,30); eucl_o.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JScrollPane eucl_o_scroll = new JScrollPane(eucl_o); eucl_o_scroll.setPreferredSize(new Dimension(490,330)); eucl_layout.putConstraint(SpringLayout.WEST, eucl_o_scroll, 5, SpringLayout.NORTH, content); eucl_layout.putConstraint(SpringLayout.NORTH, eucl_o_scroll, 180, SpringLayout.NORTH, content); euclPanel.add(eucl_o_scroll); // centerPanel.add("eucl", euclPanel); //Set the gui for the vigener cipher JPanel vigenerePanel = new JPanel(); vigenerePanel.setBackground(Color.BLUE); vigenerePanel.add(new JButton("button vigenere")); centerPanel.add("vigenere", vigenerePanel); //Set the gui for another panel JPanel emptyPanel = new JPanel(); emptyPanel.setBackground(Color.WHITE); centerPanel.add("empty", emptyPanel); //Center components content.add(centerPanel, BorderLayout.CENTER); } //This method displays the vigenere cipher in the center panel public void vigenere_gui() { card.show(centerPanel, "vigenere"); } //This method displays the Euclidean in the center panel public void eucl_gui() { card.show(centerPanel, "eucl"); } //This method resets the gui public void reset_gui() { //... } // // Extended Euclidean Algorithm for integers a & b // public void process_eucl() { //... } }
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
0
#4 Nov 10th, 2009
One, your class is named Main3, not Main1, so make sure your html file points to the actual class file. I renamed the class to Main1 and compiled it. When I did, it created Main1.class, but it also created these files too:
Make sure you copy them too. If you only copied Main1.class, you could have problems.
When I did that, it worked, both in Firefox and Internet Explorer, but it only worked in IE after I clicked the "Allow Add-On".
So try renaming Main3 to Main1 in order to match the html file, make sure you copied the $ files too, and try it again. If it still doesn't work, try clearing your browser's cache, exiting it, and opening it again.
- Main1$1.class
- Main1$2.class
- Main1$3.class
- Main1$4.class
Make sure you copy them too. If you only copied Main1.class, you could have problems.
When I did that, it worked, both in Firefox and Internet Explorer, but it only worked in IE after I clicked the "Allow Add-On".
So try renaming Main3 to Main1 in order to match the html file, make sure you copied the $ files too, and try it again. If it still doesn't work, try clearing your browser's cache, exiting it, and opening it again.
![]() |
Similar Threads
- download java applet (Java)
- java applet (Java)
- Can I run an ASP file from a Java Applet Button? (Java)
- Java Applet [Move Image] (Java)
- Java applet failed (Java)
- Java Applet Help (Java)
- calling the internet browser from a java applet (Java)
- Graph??? Help For My Project-java Applet (Java)
- where to get the java applet? (Web Browsers)
Other Threads in the Java Forum
- Previous Thread: Help with Array
- Next Thread: List.remove(List)
Views: 304 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api apple applet application arguments array arrays automation binary blackberry block bluetooth chat class classes client code component database detection developmenthelp draw eclipse encode error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie number object online oracle os page print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing template test textfields threads time title transfer tree tutorial-sample update windows working






