Title: Java User Interface Summary
Course: CPS 161: An Intro to Programming with Java - DL MM MASTER

Java User Interface Summary

Drawing Basics

- A simple JFrame based program is built, making use of setSize, setVisible, etc. in the constructor.
- In the paint method, the Graphics class can be used to draw objects on the screen. Methods demonstrated include: setColor, fillRect, drawRect, fillOval, drawLine, fillRoundRect, drawString.
- The basic coordinate system is described. Using getSize, you can always discover the size of your screen.
- The Color class is necessary to change the colors used for drawing on the screen. There are several constructors for creating the desired colors needed.

Mouse Interfaces: Spots Painting

- Interfaces are very important in java. In this section, 2 Java interfaces are demonstrated that provide a way to detect mouse clicking, and mouse movement.
- Important things to remember:
  - Have some class implement the desired interface such as MouseListener
  - Add all of the methods required to properly implement the interface (i.e. MouseListener)
  - In the added methods, you can find out information about the mouse through the parameter MouseEvent.
  - Call addMouseListener to inform the system about the class which can be called for mouse activity.
  - A call to repaint will cause the system to call your paint routine again.
- Several examples are created: Spots.java, SpotsSave.java.
- A brief introduction is made of the flexible array approach using the class ArrayList.
- To detect Mouse Motion and dragging, we add one more interface called MouseMotionListener to create the example SpotsArt.java

Mouse Interfaces: Drawing Program

- Example Simple Drawing Program: In this example we create a simple drawing program by taking the previous Shape/Rectangle/Oval drawing program and combining it with the previous work on detecting Mouse Motion.

Last Modified: June 1, 2014 1:46 PM