Monday, December 15, 2014

JAVA APPLETS

JAVA APPLETS

August 2013. The Beginning Java course ended last month. And at this time, I fully understood what I was not understanding before the beginning of the course, specifically object's attributes and methods.

For our last assignment in class, we were to write a Java applet.  Writing applets turned out to be one of the best parts of Java programming.

Here is the graphics of the applet I turned in for my assignment:


Here are parts of the comments and code I turned in for this assignment.  The entire applet is written in one class with an inner class to implement the mouse listener.

/*
Author: John Sindayen
Course: CIT130 - Beginning Java
Assignment #5 Homework #1
Due Date: 7/26/2013
*/

//MORE COMMENTS HERE

import javax.swing.*; // Needed to extend JApplet.
import java.awt.*; // Needed to draw graphics.
import java.awt.event.*; //Needed to listen to mouse events.
// Begin class definition of applet.
// Extend JApplet class.
public class House extends JApplet
{
  // Declare global boolean variables.
  boolean openRightWindow, openDoor, openLeftWindow;
  // Applet method to set up the applet.
  public void init()
  {
    // Initialize global variables.
    openLeftWindow = true;
    openRightWindow = true;
    openDoor = true;
    // Build the content pane with white background.
    getContentPane().setBackground(Color.WHITE);
    // Add mouse event listener.
    addMouseListener(new MyMouseListener());
  }
  // Method that builds the contents of the content pane.
  public void paint(Graphics g)
  {
    // Invoke the superclass paint method.
    super.paint(g);
    // Set color to black.
    g.setColor(Color.BLACK);

//MORE CODES AND COMMENTS

Drawing graphics in the computer is so much fun and when you're writing their code, that's where the excitement steps in.

Happy drawing!

John Sindayen

1 comment:

  1. Applet and swing are used in olden days under Online Java Course

    Java Online Training to develop desktop and also web applications in JAVA

    ReplyDelete