HW10 Solution1

HW10 Solution1 - setLayout(new GridLayout(items maxRating 1...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import javax.swing.* import java.awt.GridLayout public class Ratings extends JFrame { // Constructor public Ratings() { String rowsString = JOptionPane.showInputDialog("How many items?") int items = Integer.parseInt(rowsString) String[] itemNames = new String[items] int[] ratings = new int[items] int maxRating = 5 for (int i = 0 i < items i++) { itemNames[i] = JOptionPane.showInputDialog("Enter an item.") String ratingString = JOptionPane.showInputDialog("Enter a rating (1 - 5).") ratings[i] = Integer.parseInt(ratingString)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } setLayout(new GridLayout(items, maxRating + 1, 5, 5)) for(int i = 0 i < items i++) { add(new JLabel(itemNames[i])) for(int j = 0 j < maxRating j++) { if (j < ratings[i]) add(new JLabel(new ImageIcon("star.jpg"))) else add(new JLabel()) } } } // Main method public static void main(String args) { Ratings f = new Ratings() f.setTitle("Ratings") f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) f.setSize(400, 200) f.setVisible(true) } }...
View Full Document

This note was uploaded on 04/10/2008 for the course ENGR 131 taught by Professor Xiaowei during the Spring '07 term at Case Western.

Ask a homework question - tutors are online