{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MusicShopDisplay

MusicShopDisplay - SPACER GRect rect = new...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * File: MusicShopDisplay * ---------------------- * This file handles the display of album inventory * for the music shop. */ import acm.graphics.*; import java.awt.event.*; i public class MusicShopDisplay extends GCanvas implements ComponentListener { i // Constructor public MusicShopDisplay() { addComponentListener(this); lastAlbum = null; } // Display the album name, band name, and number in stock // for a single album if it is in our inventory. Otherwise, // just clear the display. public void displayInventory(Album album) { removeAll(); lastAlbum = album; if (album != null) { int numStocked = album.getNumStocked(); add(new GLabel("Album [" + album.getAlbumName() + "] by [" + album.getBandName() + "]"), 10, (getHeight() - BAR_HEIGHT) / 2 - SPACER); 1 // Display squares indicating number in inventory double nextX = SPACER; for(int i = 0; i < numStocked; i++) { double barLength = (getWidth() / (double)MAX_INVENTORY)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - SPACER; GRect rect = new GRect(nextX, (getHeight() - BAR_HEIGHT) / 2, barLength, BAR_HEIGHT); rect.setFilled(true); add(rect); nextX += barLength + SPACER; } GLabel label = new GLabel(numStocked + " in stock"); add(label, 10, (getHeight() + BAR_HEIGHT) / 2 + SPACER + label.getAscent()); } } // Whenever we need to update the display, continue to // display the last album shown public void update() { displayInventory(lastAlbum); } public void componentResized(ComponentEvent e) { update(); } public void componentHidden(ComponentEvent e) { } public void componentMoved(ComponentEvent e) { } public void componentShown(ComponentEvent e) { } p /* constants */ private static final double BAR_HEIGHT = 20; private static final double SPACER = 10; private static final int MAX_INVENTORY = 20; p /* private instance variables */ private Album lastAlbum; }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern