java - Abstract Quilt Square -


i creating abstract quilt square. have subclass of either abstractquiltsection or abstractgraphicalquiltsection , class extend 1 of these classes.

since creating text based quilt section, extended abstractquiltsection class.

there 9 abstract methods in abstractquiltsection:

**public abstract string line1...line9 (int width)** 

each of these methods return string. length of string should width parameter. i.e. if width 12, string returned should 12 characters long. line1 method returns first line of quilt section, line2 method returns second line, etc.

here confused:

each text based quilt section 9 characters high (i.e. take 9 lines), width may vary. when quilt drawn, line1, line2, line3…etc. methods called figure out characters output.

a sample quilt section width of 12 (containing quote shakespeare) might be:

............  .to.........  ......thine.  ...own......  .....self...  ..be........  .....true...  ............  shakespeare. 

i have create subclass of abstractquiltsection specializes 9 methods. in addition, may specialize textcolor , backgroundcolor methods specify colors on text based quilt section.

could check if did right?

quiltsquare

public class tomhakquiltsquare extends abstractquiltsection {     public static void main (string[]args){               abstractquiltsection square1 = new abstractquiltsection(); //cannot instantiate type abstractquiltsection         square1.line1(12);     }      @override     public string line1(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line2(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line3(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line4(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line5(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line6(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line7(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line8(int width) {         // todo auto-generated method stub         return null;     }      @override     public string line9(int width) {         // todo auto-generated method stub         return null;     } } 

abstractquiltsection

import java.awt.*; public abstract class abstractquiltsection extends abstractgraphicalquiltsection {     public abstract string line1(int width);     public abstract string line2(int width);     public abstract string line3(int width);     public abstract string line4(int width);     public abstract string line5(int width);     public abstract string line6(int width);     public abstract string line7(int width);     public abstract string line8(int width);     public abstract string line9(int width);      public color textcolor(){         return color.black;     }     public color backgroundcolor(){         return color.white;     }      public void drawquiltsection(graphics g, int width, int height) {         font f;         final int borderpix = 3;         double fontheight = (double) (height - borderpix*2)/9.0;         f = new font("courier", font.plain, (int)fontheight);          g.setcolor(backgroundcolor());         g.fillrect(0, 0, width+5, height+5);          g.setcolor(textcolor());         g.setfont(f);          fontmetrics fm = g.getfontmetrics();         int characters = (int) ((width - 2*borderpix)/fm.charwidth('0'));          g.drawstring(line1(characters), borderpix, height - borderpix - 8 * (int) fm.getascent());         g.drawstring(line2(characters), borderpix, height - borderpix - 7 * (int) fm.getascent());         g.drawstring(line3(characters), borderpix, height - borderpix - 6 * (int) fm.getascent());         g.drawstring(line4(characters), borderpix, height - borderpix - 5 * (int) fm.getascent());         g.drawstring(line5(characters), borderpix, height - borderpix - 4 * (int) fm.getascent());         g.drawstring(line6(characters), borderpix, height - borderpix - 3 * (int) fm.getascent());         g.drawstring(line7(characters), borderpix, height - borderpix - 2 * (int) fm.getascent());         g.drawstring(line8(characters), borderpix, height - borderpix - 1 * (int) fm.getascent());         g.drawstring(line9(characters), borderpix, height - borderpix);     } } 


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -