Complete the coding, in an object-oriented manner, so that the above buttons work properly.
Provide a VerticalText class. This is like a TextRectangle, but
displays its text in a vertical column, one character wide, like:
t
h
i
s
Drawing a character approx. 20 pixels lower than the previous one will suffice.
The following buttons are already provided for the advanced facilities:
Basic program - by demonstration. (Note that I will expect you to be familiar with your code. See the note on SHU plagiarism policy elsewhere.) | 35% |
Advanced parts (1) - by demo | 10% |
Advanced parts(2) - by demo | 25% |
Essay - differences - 15% Evaluation - 15% | 30% |
The demos will take place on Thurs 20th Jan - I will tell you where...
Please note that this is an individual assignment, and the University rules on copying and plagiarism apply. I will expect you to be familiar with your coding.
http://www.shu.ac.uk/schools/cms/teaching/mp/msc2004.htmIt is vital that you look here, and download the code, etc. There is also a link to 'Java for Students', which has code examples (e.g. use of files etc)
You are provided with a partially completed GUI application. It uses classes for shapes, and an ArrayList to store the shapes that are currently on screen.
It is expected that you ask for advice!!
You are provided with most of the GUI. We recommend that you don't alter this code. It contains some new event-handling: mouse-click. However, you do not need to alter this code. Most of your work is in writing new classes and responding to button events.
The code uses an 'interesting' class called ArrayList. here is some info:
This is a storage structure rather like an array, but more useful in this situation.
It keeps track of how many items are in it, and allows items to be inserted and deleted easily.
It will expand automatically when full. Unlike
an array, it is a proper class, and is accessed by methods rather than an [index]. Here is some
ArrayList code:
BankAccount b; // in tutorials... BetterAccount bBetter; ArrayList a; ... a = new ArrayList(); // an ArrayList can contain items of ANY class: a.add(b); // goes at position 0 a.add(bBetter); // goes at position 1 int n = v.size(); // n is 2 (2 elements in ArrayList currently)You can make use of size() as the limit of a for-loop, to work through each item (Items are stored at 0 upwards). ArrayList does NOT remember the class of a stored item, so you need to CAST back to the class you are using. when you have stored inherited classes as above, you must cast back to the parent class. (See the polymorphism chapter stuff in the book). So we must put:
BankAccount bTemp; bTemp = (BankAccount) v.get(1);In general, bTemp could be a BankAccount or a BetterAccount. You might need to place 'empty' methods (e.g which return 0, or which have no code between their { ... } ) to prevent any run-time errors caused by trying to use a method of the extended class with an instance of the parent. e.g. the empty method might go in the parent. Effectively we are setting up a situation in which every class will respond to certain methods, but some responses will be to 'do nothing'. Other methods of ArrayList are:
a.remove(int position); //removes item at position,shifts rest to fill gap String s = a.toString(); // returns string of whole contentsYou do NOT need to alter any of the ArrayList code in drawAllShapes(). But you will need to look at how a new shape is added, and how a selected shape is moved, in the button-handling code of the GUI.
class BankAccount { .... public BankAccount ( parameter list ) { ..... } .... }When you extend a class, Java forces you to invoke the constructor of the parent (super) class, in this way: if the first instruction in your constructor is NOT a call of the super's constructor, then a call to the default constructor will be inserted. The default constructor is one with no parameters. This is quite involved, so here is an example:
class BankAccount { .... public BankAccount(int initx){// constructor: NOT the default one ..... } .... } // ---------------------------------------------- class BetterAccount extends BankAccount { public BetterAccount(int initx) { super(initx); // first invoke constructor of BankAccount etc... } }If we omitted super(initx), then Java would try to invoke BankAccount() - the default constructor, and the only constructor it has is one with an int parameter, so we get a compilation error. BUT if BankAccount didn't have any constructor, Java would invent one behind the scenes, named BankAccount() ! So, if you never use constructors, there would be no problem. But they are useful, and are likely to be required. So remember to put a call of super(..) at the start of your constructor, to pass the appropriate parameters.