Wednesday, 2026-10-14, 5:04 PM Welcome Guest


RoyalScape Website

Main | Registration | Login | RSS
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Ghostly  
Lesson Two: Creating your very first frame
GhostlyDate: Wednesday, 2012-05-23, 2:52 PM | Message # 1
Ghost Overlord
Group: Administrators
Messages: 92
Reputation: 200
Status: Offline
In today's lesson you will be learning how to create your very first window frame using the java programming language.

Step One: Open up Notepad or any other text editor of your choice.

Step Two: Now we need to import stuff. So on the first line type:

Code
import java.awt.*;


What this does is imports all of the classes that are used to create the awt frame.

Step Three: Now it's time to create the class. So on a new line type this:

Code
public class frameExample extends Frame {


This is where we define the class. Notice that frameExample should be the same exact name as the .java file (so the file should be saved as "frameExample.java". The extends Frame part is just what we will use to make the coding easier. Don't worry about this until later.

Step 4: Create your main method. Paste the following under the previous line:

Code
public static void main(string[] args) {


Step 5: Inside this method is where we can set up our frame. So take a look at the following code:

Code
setTitle("Java AWT Frame Example");
setSize(640, 480); // The width is the first int, height is the second int
setVisible(true);


You can add more parameters to the frame but this is enough to set up the frame basics. Next time we will add more.

Step 7: Now we set up the code, all we have to do is add our closing bracket to the main method.

}

Step 8: And the same to close the class.

}

So, you should have something like this:

Code
import java.awt.*;

public class frameExample extends Frame {

public static void main(string[] args) {

setTitle("Java AWT Frame Example");
setSize(640, 480); // The width is the first int, height is the second int
setVisible(true);

}

}


So, next lesson we will add content to the frame. Don't give up now!


Ghostly - RoyalScape Developer Team
 
  • Page 1 of 1
  • 1
Search: