OO Programming with Java


Drawing tool

  1. In a main operation, create then display a window called "OS" which location is at (200,100) and size is (300,200).
javax.swing.JFrame OS = new javax.swing.JFrame("OS");
OS.setLocation(200,100);
OS.setSize(300,200);
OS.setVisible(true);
  1. By using "inheritance" and by overloading the default constructor, adapt the code such as the main can be simplified to:
new OS();
  1. To exit the program, add in the default constructor the following statement then by using Eclipse IDE implements the required operations to correct the code. Next, find the correct position where to add a System.exit(0).
this.addWindowListener(new java.awt.event.WindowListener() {});
  1. Next, find the statement to exit the application when pressing the key 'q'.
    To proceed, you can use the KeyEvent.getKeyChar() operation.
  2. Now a) make the window undecorated and b) make it "full screen" with:
GraphicsEnvironment.getLocalGraphicsEnvironment()
  .getDefaultScreenDevice()
  .setFullScreenWindow(this);
  1. By overloading the paint(Graphics g) draw a circle on the screen.
  2. Next a) create a class Circle with a paint operation, b) add an attribute c:Circle to the application, and c) rewrite the paint operation to display the circle.
  3. Adapt the application to display the circle at the mouse's click location.
  4. Change the circle to a list of circles and add circles on each click.
  5. Extend the application such as: by pressing 'a' will add circles and pressing 's' will select a circle - a selected circle will be in another color.
    To proceed, you can add a selected attribute to circles with two operations: select(x,y) that changes the attribute depending on a click location and unselect to reset the attribute.
  6. Adapt the application such as the circles' list is "persistent".
  7. Create an executable jar for the application (that contains source code).

source