• 0

Java Rating?


Question

For coursework I have to create a media player which allows you to rate . What I need to know is it possible to have the ratings appear as stars like on wmp. I currently have a drop down list going from 1 to 5, but it looks a bit of a mess.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Its a string of 5 asterisks. The substring method selects the first 1-5 of those stars, depending on the value of the int ratingOneToFive. Ie, input 1 into it, it gives "*", put 5 into it, it gives "*****". You can this display this anyway you want - probably a JLabel.

Link to comment
Share on other sites

  • 0

From what I read it seems that the problem is the GUI, the actual storing of the value should be fairly trivial (just get an int from 0 to 5, 0 being unrated). if you're using images with a JLabel then just add a switch for the imagepath given a value.

Post screenshots, BTW.

Link to comment
Share on other sites

  • 0

Add mouse click events (and mouse hover events if you want to get fancy) to a series of images. Clicking one will set the rating and light up the rest.

☆☆☆☆☆

Clicking the third star would result in:

★★★☆☆

For the code you would do something like

sub onclick image
for 1 to 5
reset every star to blank

store rating based off image number

for 1 to image number
swap star image to filled

For initial loading, you could do this.

sub onload
if rating = 0 return
else
for 1 to rating
load filled star
for rating+1 to 5
load empty star

I don't know a bit of Java GUI or how your program is structured, but you would do something vaguely similar.

An even easier way would just be using labels with a string using the unicode stars that I printed. You would just be updating the string.

Edited by Xilo
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.