Question

Illustrate understanding of inheritance by building a GUI with Java. Your program will enable the user to create and view simple animations in ASCII.
Ascii animation is a nearly lost art form, but it involves creating moving images using nothing but the standard ASCII characters.
Your project is to build a simple GUI that enables the user to create and view ASCII animations. Requirements:
• Use a JFrame or JApplet as the primary interface
• Extend whatever Swing elements you need to create the animation
• Use at least one interface to handle events
• Incorporate a custom panel to accept the animations
• Include buttons or a menu interface to allow moving between frames, saving and loading
• User should be able to edit any frame
• User should be able to navigate between frames
• There should be some mechanism for saving and loading animations
• Animations should be stored via a double-linked list
• Use Object serialization to store and retrieve data to the file
• The best example will have NO loops or arrays.
The AsciiAnim class
Notes about the AsciiAnim class
• It already builds the basic functionality and GUI, Do Not change this for the basic version of your program
• I have added all the buttons and event-handler functionality
• I have even added a Swing timer, but you may need to look this up to see how it works
• My code expects an AsciiCanvas object, which of course you will have to build
• Look at my code to get a sense what the AsciiCanvas should be able to do.
The asciiCanvas
You're expected to build the AsciiCanvas class. This class should have the following capabilities:
• be an extension of JTextArea or something similar
• include the animation (as a linked list of some sort)
• display text in a monospace font
• have methods for moving back and forth in the animation
• have methods for saving and loading the animation
• support animations of at least ten frames
• support the animation button given in the AsciiAnim class
Linked List Animation
• Store your animation as double-linked list.
• You'll need some sort of node class (I called my node AFrame.)
• Each instance of the node represents a single frame of animation.
• Do NOT build an array of nodes.
• Each node should have a next and prev attribute, which will contain references to the appropriate nodes.
• Use the null indicator to describe the beginning and end of the list.
• Make your node serializable to simplify saving and loading
• Your AsciiCanvas will only need two specific instances of the node class:
o head points to the top node on the list
o current points to the current node
• You should only need to save and load the head. Other nodes will come along with the head
As much of the animation code as possible should belong to the AsciiCanvas. The main program shouldn't actually be saving files or switching frames. The main program should be sending requests to the canvas to do the actual work when possible. Encapsulate!
Final deliverable is a zip file with your .java source files and a makefile with make, make run and make clean commands.
Blackbelt extension
There are many ways to extend this project. One obvious extension is to add insert and delete functionality, or the ability to manage multiple animations....

---------------------------------------------^^^^Homework^^^^------------------------------------------------------
_____________________________Extras___________________________________________
USER INTERFACE
//AsciiAnim.java

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class AsciiAnim extends JFrame implements ActionListener{

AsciiCanvas cnvAnim = new AsciiCanvas();
JButton btnPrev = new JButton("prev");
JButton btnNext = new JButton("next");
JButton btnSave = new JButton("save");
JButton btnLoad = new JButton("load");
JButton btnAnim = new JButton("animate");

JPanel pnlSouth = new JPanel();
Timer timer = new Timer(100, this);

boolean animating = false;

public AsciiAnim(){
   
    this.setUpGUI();
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
    this.setSize(640, 480);
} // end constructor

public void setUpGUI(){
    //like it says, set up GUI
    Container pnlMain = this.getContentPane();
   
    pnlSouth.setLayout(new FlowLayout());
    pnlMain.add(cnvAnim, BorderLayout.CENTER);
    pnlMain.add(pnlSouth, BorderLayout.SOUTH);

    pnlSouth.add(btnPrev);
    pnlSouth.add(btnNext);
    pnlSouth.add(btnAnim);
    pnlSouth.add(btnSave);
    pnlSouth.add(btnLoad);

    //add action listeners
    btnPrev.addActionListener(this);
    btnNext.addActionListener(this);
    btnAnim.addActionListener(this);
    btnSave.addActionListener(this);
    btnLoad.addActionListener(this);

} // end setUpGUI

public void actionPerformed(ActionEvent e){
    if (e.getSource() == btnPrev){
      cnvAnim.prevFrame();
    } else if (e.getSource() == btnNext){
      cnvAnim.nextFrame();
    } else if (e.getSource() == btnAnim){
      //change the animation status
      if (timer.isRunning()){
       btnAnim.setText("animate");
       timer.stop();
       this.animating = false;
      } else {
       btnAnim.setText("stop");
       timer.start();
       this.animating = true;
      } // end if
    } else if (e.getSource() == btnSave){
      cnvAnim.save();
    } else if (e.getSource() == btnLoad){
      cnvAnim.load();
    } else if (this.animating == true){
      cnvAnim.anim();
    } else {
      System.out.println("action not defined");
    } // end if
} // end actionPerformed

public static void main(String[] args){
    new AsciiAnim();
} // end main


} // end class def

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

class AsciiCanvas extends JTextArea {

    public static final int COL = 70;
    public static final int ROW = 14;

    public static final String FILE_NAME = "database";
    private static final int FONT_POINTS = 15;

    private int frameNum;
    private AFrame head;
    private AFrame current;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$60.00

or $1 if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats