// Jay Summet (GaTech) // // An example of creating a subclass of Picture and adding a // new object attribute (variable) and behaviors (methods). public class BetterPicture extends Picture { private String copyRight; public static void main(String [] args) { BetterPicture bp = new BetterPicture( FileChooser.pickAFile() ); bp.show(); Picture p = bp.getARow(1); p.show(); bp.setCopyright("Jay Summet"); System.out.println("Copyright is owned by:" + bp.getCopyright() ); } // end main // Call the picture(width,height) constructor public BetterPicture(int width, int height, String copyright){ super( width,height); this.copyRight = copyright; } public String getCopyright(){ return this.copyRight; } public void setCopyright( String newString) { this.copyRight = newString; } public BetterPicture(String fileName) { super(fileName); } // end Constructor BetterPicture( string filename) // This object method returns a picture that is one pixel high // copied from rowNum in the current picture. public Picture getARow( int rowNum) { int myWidth = this.getWidth(); Picture p = new Picture( myWidth, 1 ); for(int i = 0; i < myWidth; i = i + 1) { Pixel srcPix = this.getPixel(i ,rowNum); java.awt.Color c = srcPix.getColor(); Pixel dstPix = p.getPixel(i,0); dstPix.setColor(c); } // end for i in width of picture //System.out.println("my Width is:" + myWidth); return p; } // end public Picture aRow } // end class BetterPicture