Showing posts with label FRAME WINDOW. Show all posts
Showing posts with label FRAME WINDOW. Show all posts

Wednesday, 26 February 2014


How to  Create an AWT-based application.

Creating applets is the most commom use for java's AWT
But,it is possible to create stand-alone AWT based applications to do this

  • simply create an instance of the window or windows you need inside main()
  • e.g. create frame window with in main()

The example program is  shown below:

// Create an AWT-based application.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
// Create a frame window.
public class AppWindow extends Frame 
String keymsg = "This is a test.";
String mousemsg = "";
int mouseX=30, mouseY=30;
public AppWindow() 
addKeyListener(new MyKeyAdapter(this));
addMouseListener(new MyMouseAdapter(this));
addWindowListener(new MyWindowAdapter());
public void paint(Graphics g) {
g.drawString(keymsg, 10, 40);
g.drawString(mousemsg, mouseX, mouseY);


How to create a child frame window from within an applet...........

Creating a new frame window from within an applet is actually quite easy.
The following steps may be used to do it,
  • Create a subclass of Frame
  • Override any of the standard window methods,such as init(),start(),stop(),and paint().
  • Implement the windowClosing() method of the windowlistener interface,calling setVisible(false)when the window is closed
  • Once you have defined a Frame subclass,you can create an object of that class.But it will note be initially visible
  • When created,the window is given a default height and width
  • You can set the size of the window explicitly by calling the setSize() method
The example program is  shown below: