Monday, February 2, 2009

Tues Feb 3: first GUI application! #1

OK Java Koderz, as promised, today we will be working with a GUI application. This is a program which doesn't need a webpage to run inside; besides that there are several other differences:


A) An applet just sort of EXISTS; to have an application, you need a "Frame". You declare a frame like this:


Frame f1;


B) applets have init methods; applications have constructors. A constructor is easy to write: you just take your class name and stick a ( ) at the end of it. Throw in an opening and closing curly brace { and }, and you've got a constructor. It looks something like this:


FirstFrame( )
{


}


C) An applet made in textPad automatically sizes itself; in an application, you need to declare the size AND the location, kind of like this:


f1.setSize(400,450);
f1.setLocation(120,149);

btw, the two lines of code above would go inside the constructor!

D) an applet just shows up when you view the webpage; for an application to be visible, you have to SHOW it. You can declare a frame and size it, but it still won't show until you add this line to your constructor:
f1.show( );

E) all applications have main methods, and this one is no exception. The main method here will do only one thing: make a new object from the class you've declared and constructed


Fear not: I will be giving you a complete code sheet, so you won't have to figure out where everything goes. Let's do this one, then move on to code where our application can actually DO something


cheers,
Uncle Paulie

No comments:

Post a Comment