Results 1 to 2 of 2
- 05-20-2009, 04:04 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
"The public type AppletFrame must be defined in its own file" what is it?
i am executing this program in "eclipse"..XML Code://Create a child frame window from within an applet package Applets; import java.awt.*; import java.applet.*; import java.awt.event.*; /* * <applet code="SampleFrame" width=300 height=50> * </applet> * */ class SampleFrame extends Frame{ SampleFrame(String title){ super(title); //create an object to handle window events MyWindowAdapter adapter=new MyWindowAdapter(this); //register it to receive those events addWindowListener(adapter); } public void paint(Graphics g){ g.drawString("This is in Frame window",10,40); } } class MyWindowAdapter extends WindowAdapter{ SampleFrame sampleFrame; public MyWindowAdapter(SampleFrame sampleFrame){ this.sampleFrame=sampleFrame; } public void windowClosing(WindowEvent we){ sampleFrame.setVisible(false); } } //create Frame window public class AppletFrame extends Applet{ Frame f; public void init(){ f=new SampleFrame("A Frame Window"); f.setSize(250,250); f.setVisible(true); } public void start(){ f.setVisible(true); } public void stop(){ f.setVisible(false); } public void paint(Graphics g){ g.drawString("This is A Applet Window",20,20); } }
Error is...
XML Code:java.lang.Error: Unresolved compilation problem: The public type AppletFrame must be defined in its own file at Applets.AppletFrame.<init>(SampleFrame.java:33) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at sun.applet.AppletPanel.createApplet(Unknown Source) at sun.applet.AppletPanel.runLoader(Unknown Source) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
Thanks Sir.
- 05-20-2009, 08:46 PM #2
what is it?
Put this class in a separate file or remove the public modifier from its declaration, ie, change this
to thisJava Code:public class AppletFrame extends Applet{
In general, only one outer class in any given file may have the public modifier and its name must be the same name as the fileName.Java Code:class AppletFrame extends Applet{
To run an applet from the prompt (like an application) try this approach:
Java Code:public class Pseudo extends JApplet { public void init() { // everything as usual for your applet } /** Add this convenience method. */ public static void main(String[] args) { JApplet applet = Pseudo(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(applet); f.setSize(300,50); f.setLocation(100,100); applet.init(); // if you have overidden the applet [i]start[/i] method applet.start(); f.setVisible(true); } }
Similar Threads
-
Getting access denied error while importing file using input type="file" with IE7
By sarang1 in forum Advanced JavaReplies: 6Last Post: 02-10-2011, 09:55 AM -
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
Count lines cointaining "word" in input file
By gwithey in forum New To JavaReplies: 5Last Post: 04-02-2009, 05:23 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks