Notes on Java

  1. GUI Applications
  2. Object-Oriented Design
  3. Instance vs Static Methods
  4. FAQs

Setting up a GUI Application

Setting up a full-fledged GUI application in Java sounds a lot more complicated than it really is. The steps are:

  1. Plan your main JPanel: Plan the first JPanel and nest all the other parts within it.
  2. First, setup the separate JPanels you'll put in the main JPanel: Setup separate JPanels for the input display and the output display. Then assign layouts to each of them. E.g., you might setup a JPanel for a block of buttons and then put them on a GridLayout.
  3. Setup the main JPanel now: Put all of the individual JPanels into your main JPanel and use another layout manager to organize them.

Program Development with Java/Eclipse

Object-Oriented Design using the MVC Architecture

One of the best ways to approach building an Object-Oriented Program (OOP) is to write down the program requirements. Then, identify all the nouns and verbs in the requirements. Each of the nouns suggests an object/class and each of the verbs suggests a function/method.

In particular, the Model-View-Controller (MVC) pattern says there are three major abstract components in software: a Model (which manages the data and the behaviour; as a quick aside, what does that sound like when I talk about something that encapsulates data and their associated behaviours?), a View (which renders the model/displays the information; i.e., the GUI for us), and a Controller (which interacts with the user as well as determining the interaction of the Model and View and telling them to change as needed).

  1. Model:
  2. View:
  3. Controller:

All along, please consider how this would be different from cut-and-paste and starting by simply coding away without any design approach?

If you're having trouble getting started, try setting up a blank lab/program and copying-and-pasting a working sample program (e.g., from the book) and play with it to see exactly what it does and how. Then you can go back and correct the problems your own lab or program might be having once you've worked out the logic and design above.

Here is another great link for the MVC pattern.

Instance vs Static Methods

Difference between instance and static methods: there is only a single copy of any method, static or instance; the only difference is that instance methods are called with a context that includes an instance (accessible via the this) variable. A static method can thus be invoked by using the class name directly.

FAQs


Ricky J. Sethi, PhD <rickys@sethi.org>
Last updated: Friday, June 15 2018
(www.sethi.org/tutorials/notes_java.shtml)