您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)

 

Content Index

Content Page # 7

Example of creating the main window with subclass of Frame

A simple application using the approach would require 2 source files, MainWindow.java:

import java.awt.*;

class MainWindow extends Frame

  {

  // MainWindow methods go here

  public MainWindow() // constructor

    {

    super("My program’s title");

    setSize (300, 300);

    }

  } // class

and MyWindowApp.java

class MyWindowApp

  {

  public static void main(String args[])

    {

    MainWindow mainWindow = new MainWindow();

    mainWindow.setVisible (true);

    } 

  } // class

This application does not handle window events the window will not close when we try to close the applet or click on top right hand button 'x'. to stop the MyWindowApp from Kawa, you need to select stop run from the Build pull down menu.

When running this application simple displays an empty Frame window with the title ‘My program’s title’:

image9.gif (1885 bytes)

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg