![]() We can do this by setting its attributes, such as its general appearance, its size, what it contains, and more.įor starters, let's make sure that when the window is closed, the application also stops. It handles the complex task of telling the computer how to draw the window to the screen, and leaves us the fun part of deciding how it's going to look. The JFrame class will do most of the work of creating the window for us. You can think of "frame" as the window for our Java application. What this line does is create a new instance of a JFrame object called "frame". Type in the following code, remembering to place it between the curly brackets of the createWindow function: Now, let's look at creating the window using a JFrame object. Anytime the createWindow function is called, the Java application will create and display a window using this code. With this in mind, I'm grouping all the Java code that deals with creating the window into one function.Įnter the createWindow function definition:Īll the code to create the window goes between the function’s curly brackets. This design makes the program more readable, and if you want to run the same set of instructions again, all you have to do is run the function. It's good programming style to group sets of similar commands into functions. Microsoft product screen shot(s) reprinted with permission from Microsoft Corporation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |