Showing posts with label import java.awt.Frame. setSize. Show all posts
Showing posts with label import java.awt.Frame. setSize. Show all posts

Wednesday, 20 August 2014

How to Display an Empty Frame in Java

I created the file shown below using vi then compiled it and ran it:

andrew@UBUNTU:~/Java$ cat AndrewsFrame.java
import java.awt.Frame;
public class AndrewsFrame extends Frame
{
public AndrewsFrame()
  {
  super("Andrew's Frame");
  setSize(500,300);
  setVisible(true);
  }
public static void main (String args[])
  {
  AndrewsFrame af = new AndrewsFrame();
  }
}
andrew@UBUNTU:~/Java$ javac AndrewsFrame.java
andrew@UBUNTU:~/Java$ java AndrewsFrame


This displayed the small empty frame shown below. I found that I could move it by dragging and dropping the title bar and minimize and maximize it too. I could also resize it by clicking the edge of the frame and dragging it in the usual way. However, to close the frame, I had to return to the UNIX prompt and type Ctrl+C. I hope to show a better way to do this in a future post. As usual, click on the image to enlarge it and bring it into focus: