Re: Simple Applet Troubles
Your code doesn't have a valid init() method -- check your spelling:
Code :
// this should be spelled "init"
public void inti() {
// ...
}
Don't forget to use @Override annotations to make sure that the methods you think you are overriding you actually are overriding:
Code :
@Override
public void inti() { // this will cause a compilation error until the spelling is fixed.
// ...
}
Also you'll want to draw in the paintComponent method of a JComponent such as a JPanel rather than draw in the paint method of a JApplet or any other top-level window.
Re: Simple Applet Troubles
.. Thank you first off. I am kind of in one of those facepalm moments now, Also thank you for the tips with @Override and the JComponent. Really appreciate it.
While we are on the subject, If you don't mind would you be able to go into detail about JComponent / JPanal vs JApplet ?
Re: Simple Applet Troubles
Quote:
Originally Posted by
Veldimare
Also getting a warning @ public class Practice : The serializable class Practice does not declare a static final serialVersionUID field of type long.
If anyone knows what the means that would be super helpful, Any help is much appreciated.
Your Practice class is extending JApplet, a class that implements the Serializable interface. This means that Practice by extension also implements this interface, and the interface's contract stipulates that classes that implement it should declare and initialize a static final serialVersionUID long variable. This variable is useful for if you want to serialize or de-serialize objects since the version ID will let you know if the objects you are dealing with are the correct expected version. For instance you wouldn't want to de-serialize a version 1.0 object into code that uses the 2.0 version of your class.
But having said all this, I'm going to suggest you ignore it all since it is *very* rare that you'll ever want to serialize a class that extends JApplet or any Swing component. Rather if you use serialization, you'll likely want to serialize the logical part of your program, not its GUI representation. I suggest that you place the @SuppressWarnings("serial") annotation just above your Practice class declaration which will tell the compiler not to give you this warning.
Re: Simple Applet Troubles
Quote:
Originally Posted by
Veldimare
.. Thank you first off. I am kind of in one of those facepalm moments now, Also thank you for the tips with @Override and the JComponent. Really appreciate it.
You're quite welcome!
Quote:
While we are on the subject, If you don't mind would you be able to go into detail about JComponent / JPanal vs JApplet ?
When you paint in a top-level window's paint method, you are painting over not just the work portion of the GUI but also its borders and child components, and this can result in some unintended side effects. Also since the paint method of a top-level window can only use drawing code from AWT (they are so-called "heavy-weight" components), you lose some of the benefits of Swing painting including its default double-buffering. This means that animations drawn in a JPanel's paintComponent method will likely flow much more smoothly than the same animation drawn in the paint method of a JFrame or JApplet. My classes that extend JApplet are usually very very small and only have code to create the GUI (usually code that creates a JPanel) and then places the GUI in my applet's contentPane, and that's it.
Re: Simple Applet Troubles
Awsome, Thank you very much. It makes more sense now. Alright back to studying.
Re: Simple Applet Troubles
Re: Simple Applet Troubles
Quote:
Originally Posted by
bruizer
Well figured it states applet troubles / and creating new threads and clogging up others posting I figured to keep it within the same category or topic / thanks though no worries.
But your question has nothing to do with the original question and so really doesn't belong in his thread.
Quote:
I'll just keep trying on my own thx.
No worries, but if you get stuck, again consider creating a new question in this forum. It's not hard to do and it costs nothing.