Running a Graphical Application Core Java

The Welcome program was not terribly exciting. Next, we will demonstrate a graphical application. This program is a simple image file viewer that just loads and displays animage. Again, let us first compile and run it from the command line.

  1. Open a shell window.
  2. Change to the directory CoreJavaBook/v1ch02/ImageViewer.
  3. Enter the following:
    java ImageViewer

A new program window pops up with our ImageViewer application.

Running the ImageViewer application

Running the ImageViewer application

Now, select File -> Open and look for an image file to open. (We supplied a couple ofsample files in the same directory.)

To close the program, click on the Close box in the title bar or pull down the system menu and close the program. (To compile and run this program inside a text editor or an integrated development environment, do the same as before. For example, for Emacs, choose JDE -> Compile, then choose JDE -> Run App.)

Running a Graphical Application

We hope that you find this program interesting and useful. Have a quick look at thesource code. The program is substantially longer than the first program, but it is not terribly complex if you consider how much code it would take in C or C++ to write a similar application. In Visual Basic, of course, it is easy to write or, rather, drag and drop,such a program. The JDK does not have a visual interface builder, so you need to write code for everything. You learn how to write graphical programs like this in later sections.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Core Java Topics