Hi,
Sorry if this is in the wrong place, i didnt know whether to post it under applets or under what wrong with my code...
So, i have an applet that im trying to run in the browser with this HTML code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- This file automatically generated by BlueJ Java Development --> <!-- Environment. It is regenerated automatically each time the --> <!-- applet is run. Any manual changes made to file will be lost --> <!-- when the applet is next run inside BlueJ. Save into a --> <!-- directory outside of the package directory if you want to --> <!-- preserve this file. --> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>FindAddApplet Applet</title> </head> <body> <h1>FindAddApplet Applet</h1> <hr> <applet code="FindAddApplet.class" width=500 height=500 codebase="/home/pottsie/TutorProgram" archive="file:/usr/share/bluej/bluejcore.jar,file:/usr/share/bluej/junit-4.8.2.jar,file:/home/pottsie/TutorProgram/" alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." > Your browser is ignoring the <APPLET> tag! </applet> <hr> </body> </html>
However each time i run it i get the error "Start: Applet not initialized"...
This is the code i am trying to run:
import java.applet.*; import java.awt.*; import java.util.*; import java.awt.event.*; import javax.swing.JEditorPane; import javax.swing.*; public class FindAddApplet extends Applet implements ActionListener { private JLabel jcomp1; private JButton nextButton; private JButton prevButton; private JPanel contentPanel; //content layout private CardLayout cardLayout; //jpanel cards ClassYearCard classYearCard; PeriodCard periodCard; NameEmailCard nameEmailCard; //labels for cards private int currentLabel = 0; String classYearLabel = (""+1); String periodCardLabel = (""+2); String nameEmailLabel = (""+0); public void init() { //construct components cardLayout = new CardLayout(); jcomp1 = new JLabel ("Main Page"); nextButton = new JButton ("Next >"); prevButton = new JButton ("< Previous"); contentPanel = new JPanel (); classYearCard = new ClassYearCard(); periodCard = new PeriodCard(); nameEmailCard = new NameEmailCard(); //adjust size and set layout setPreferredSize (new Dimension (415, 414)); setLayout (null); //add components add (jcomp1); add (nextButton); nextButton.addActionListener(this); add (prevButton); prevButton.addActionListener(this); add (contentPanel); contentPanel.setLayout(cardLayout); //sets layout of contentPanel //set content layout //add stuff to panel contentPanel.add(nameEmailCard, nameEmailLabel); contentPanel.add(classYearCard, classYearLabel); contentPanel.add(periodCard, periodCardLabel); //set component bounds (only needed by Absolute Positioning) jcomp1.setBounds (25, 5, 100, 25); nextButton.setBounds (205, 320, 110, 25); prevButton.setBounds (85, 320, 110, 25); contentPanel.setBounds (15, 30, 300, 285); } public void start() { } public void actionPerformed(ActionEvent e){ if (e.getSource() == nextButton){ currentLabel++; cardLayout.show(contentPanel, (""+currentLabel)); } if (e.getSource() == prevButton){ currentLabel--; cardLayout.show(contentPanel, (""+currentLabel)); } } public void stop() { } public void destroy() { } }
The code runs fine in the appletveiwer, so im guessing its the HTML, but i thought it would be better to post both