help neede please
i am currently working on an assignment for university. I have to design a jukebox that plays music when a track is selected from a genre. I have got a finished one, but i posted on here to get help and a person kindly helped me but i want to do it for my self.
my problem is i have created 2 choices one choice contains the tracks for the rock genre, the other for pop genre,i have set them as visible false. i have a choice box called change genre which has in it the 2 genre's rock and pop i am trying to write the code so that when a choice is made from the genre choice then the correct list is displayed. I have read every tutorial i can find but i just cannot seem to take it in. can anyone help me. the code i have written so far is as follows:
/**
* @(#)JJJB.java
*
* JJJB Applet application
*
* @author
* @version 1.00 2007/1/4
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.applet.Applet;
import java.net.URL;
publicclass JJJBextends Appletimplements ItemListener{
private Panel controlPanel,topPanel;
private Panel middPanel;
private Choice rockChoice,popChoice,genre;
private Button play,stop;
private String[] rocklist;
private String[] poplist;
private DrawingCanvas DrawingCanvas;
private AudioClip[]rockMusic;
private AudioClip[]popMusic;
private AudioClipcurrent;
private URL url1, url2, url3, url4, url5, url6, url7, url8, url9, url10,url11;
publicvoid init(){
try
{
url1=new URL ("file","localhost","song1.wav");
url2=new URL ("file","localhost","song2.wav");
url3=new URL ("file","localhost","song3.wav");
url4=new URL ("file","localhost","song4.wav");
url5=new URL ("file","localhost","song5.wav");
url6=new URL ("file","localhost","song6.wav");
url7=new URL ("file","localhost","song7.wav");
url8=new URL ("file","localhost","song8.wav");
url9=new URL ("file","localhost","song9.wav");
url10=new URL ("file","localhost","song10.wav");
url11=new URL ("fil","localhost","song11.wav");
}
catch(Exception exception)
{
}
//ARRAYS
rockMusic =new AudioClip[6];
rockMusic[0] =null;
rockMusic[1] = Applet.newAudioClip(url1);
rockMusic[2] = Applet.newAudioClip(url2);
rockMusic[3] = Applet.newAudioClip(url3);
rockMusic[4] = Applet.newAudioClip(url4);
rockMusic[5] = Applet.newAudioClip(url5);
//-
popMusic =new AudioClip[6];
popMusic[0] =null;
popMusic[1] = Applet.newAudioClip(url6);
popMusic[2] = Applet.newAudioClip(url7);
popMusic[3] = Applet.newAudioClip(url8);
popMusic[4] = Applet.newAudioClip(url9);
popMusic[5] = Applet.newAudioClip(url10);
setLayout(new BorderLayout());
controlPanel =new Panel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.blue);
stop =new Button("STOP");
stop.setBackground(Color.cyan);
play =new Button("PLAY");
play.setBackground(Color.cyan);
controlPanel.add(stop);
controlPanel.add(play);
add(controlPanel,"South");
rockChoice =new Choice();
popChoice =new Choice();
rocklist =new String[]{
"Select Rock Song","Turn up The Sun","Mucky Fingers","LYLA","Love Like A Bomb","A Bell Will Ring","Let There BE Love"};
for (int i = 0; i < rocklist.length; i++)
rockChoice.add(rocklist[i]);
poplist =new String[]{
"Select Pop Song","The Meaning Of Soul","Guess God Thinks I Am Able","Part Of The Queue",
"Keep The Dream Alive"};
genre=new Choice();
genre.add("Rock");
genre.add("Pop");
for (int i = 0; i < poplist.length; i++)
popChoice.add(poplist[i]);
rockChoice.addItemListener(this);
popChoice.addItemListener(this);
DrawingCanvas drawingCanvas =new DrawingCanvas();
topPanel =new Panel();
topPanel.setLayout(new BorderLayout());
topPanel.setBackground(Color.black);
topPanel.add(drawingCanvas,"Center");
add(topPanel,"North");
middPanel =new Panel();
middPanel.setLayout(new FlowLayout());
middPanel.setBackground(Color.red);
middPanel.add(genre);
middPanel.add(rockChoice);
middPanel.add(popChoice);
add(middPanel,"Center");
}
privateclass DrawingCanvasextends Canvas{
private DrawingCanvas(){
setSize(100,200);
}
publicvoid paint(Graphics g){
g.drawString("Welcome to Java!!", 50, 60 );
}
}
publicvoid itemStateChanged(ItemEvent ie){
if(genre.getSelectedItem()=="Rock"){
rockChoice.setVisible(true);
popChoice.setVisible(false);
}
}
}
Message was edited by:
fowlergod09
You didn't explain your problem well, but:
if(genre.getSelectedItem()=="Rock"){
should use ".equals" instead of "==":
if(genre.getSelectedItem().equals("Rock")){
Always use ".equals" when comparing String values for equality.
You need to also handle when the selected item is "Pop".
Yes you should really never use == for comparing strings like post above. I tried your code with equalsIgnoreCase
if(genre.getSelectedItem().equalsIgnoreCase("Rock")){
rockChoice.setVisible(true);
popChoice.setVisible(false);
}
if(genre.getSelectedItem().equalsIgnoreCase("Pop")){
rockChoice.setVisible(false);
popChoice.setVisible(true);
}
repaint();
Is this something you have tried?
try it and see if the result is something you want.
EDIT
you didnt really register an itemlistener to genre...
add that
genre.addItemListener(this);
after you set Rock and Pop to Genre
Message was edited by:
Bz_Unknown
having re-read my question i take your point, it was a poor question.
i have a choicebox called'genre' with 2 selections inside"rock" and "pop". I have a choice box called 'popchoice' with track choices in relating to the 'pop' genre and the other called 'rockchoice' with trackchoices relating to the 'pop' genre.
i have set rockchoice and popchoice as setVisible false. I am trying to write the code so that when a choice is made from the genre choicebox(either rock or pop)the correct list becomes visible. i will post my full code if it helps.
/**
* @(#)JJJB.java
*
* JJJB Applet application
*
* @author
* @version 1.00 2007/1/4
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.applet.Applet;
import java.net.URL;
public class JJJB extends Applet implements ItemListener{
private Panel controlPanel,topPanel;
private Panel middPanel;
private Choice rockChoice,popChoice,genre;
private Button play,stop;
private String[] rocklist;
private String[] poplist;
private DrawingCanvas DrawingCanvas;
private AudioClip[]rockMusic;
private AudioClip[]popMusic;
private AudioClipcurrent;
private URL url1, url2, url3, url4, url5, url6, url7, url8, url9, url10,url11;
public void init() {
try
{
url1=new URL ("file", "localhost","song1.wav");
url2=new URL ("file", "localhost","song2.wav");
url3=new URL ("file", "localhost","song3.wav");
url4=new URL ("file", "localhost","song4.wav");
url5=new URL ("file", "localhost","song5.wav");
url6=new URL ("file", "localhost","song6.wav");
url7=new URL ("file", "localhost","song7.wav");
url8=new URL ("file", "localhost","song8.wav");
url9=new URL ("file", "localhost","song9.wav");
url10=new URL ("file", "localhost","song10.wav");
url11=new URL ("fil", "localhost","song11.wav");
}
catch(Exception exception)
{
}
//ARRAYS
rockMusic = new AudioClip[6];
rockMusic[0] = null;
rockMusic[1] = Applet.newAudioClip(url1);
rockMusic[2] = Applet.newAudioClip(url2);
rockMusic[3] = Applet.newAudioClip(url3);
rockMusic[4] = Applet.newAudioClip(url4);
rockMusic[5] = Applet.newAudioClip(url5);
//-
popMusic = new AudioClip[6];
popMusic[0] = null;
popMusic[1] = Applet.newAudioClip(url6);
popMusic[2] = Applet.newAudioClip(url7);
popMusic[3] = Applet.newAudioClip(url8);
popMusic[4] = Applet.newAudioClip(url9);
popMusic[5] = Applet.newAudioClip(url10);
setLayout(new BorderLayout());
controlPanel = new Panel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.blue);
stop = new Button("STOP");
stop.setBackground(Color.cyan);
play = new Button("PLAY");
play.setBackground(Color.cyan);
controlPanel.add(stop);
controlPanel.add(play);
add(controlPanel,"South");
rockChoice = new Choice();
popChoice = new Choice();
rocklist = new String[]{
"Select Rock Song","Turn up The Sun", "Mucky Fingers", "LYLA", "Love Like A Bomb", "A Bell Will Ring", "Let There BE Love" };
for (int i = 0; i < rocklist.length; i++)
rockChoice.add(rocklist[i]);
poplist = new String[]{
"Select Pop Song","The Meaning Of Soul", "Guess God Thinks I Am Able", "Part Of The Queue",
"Keep The Dream Alive" };
genre= new Choice();
genre.add("Rock");
genre.add("Pop");
for (int i = 0; i < poplist.length; i++)
popChoice.add(poplist[i]);
rockChoice.addItemListener(this);
popChoice.addItemListener(this);
DrawingCanvas drawingCanvas = new DrawingCanvas();
topPanel = new Panel();
topPanel.setLayout(new BorderLayout());
topPanel.setBackground(Color.black);
topPanel.add(drawingCanvas,"Center");
add(topPanel,"North");
middPanel = new Panel();
middPanel.setLayout(new FlowLayout());
middPanel.setBackground(Color.red);
middPanel.add(genre);
middPanel.add(rockChoice);
middPanel.add(popChoice);
add(middPanel,"Center");
}
private class DrawingCanvas extends Canvas{
private DrawingCanvas(){
setSize(100,200);
}
public void paint(Graphics g) {
g.drawString("Welcome to Java!!", 50, 60 );
}
}
public void itemStateChanged(ItemEvent ie){
if(genre.getSelectedItem().equals("Rock")){
rockChoice.setVisible(true);
popChoice.setVisible(false);
}
else if(genre.getSelectedItem().equals("Pop")){
popChoice.setVisible(true);
rockChoice.setVisible(false);
}
}
}
see my earlier post, just register an item listener after genre.add("rock") and genre.add("pop").
thanks bz works a treat now.
can i now register a listener on the play and stop buttons for when a choice is made from the rocklist? i am confused because buttons use action listeners and choices use item listeners.
yes you can. for example
playButton.addActionListener(this);
stopButton.addActionListener(this);
You need to implement ActionListener at the top of your code
You also need to code
public void actionPerformed(ActionEvent e) {}
to handle button actions.
You know how to code this right?
-Bz
yes i know that bit bz, it is when it comes to writing the argument i struggle. how does this sound
private class ChoiceListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if (current != null)
current.stop();
Choicekbox chk = genreChoice.getSelectedCheckbox();
if(chk.getLabel()==揜ock")
current = RockMusic[technoChoice.getSelectedIndex()];
else if (chk.getLabel()==揚op")
current = PopMusic[tranceChoice.getSelectedIndex()];
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
if (current != null)
current.stop();
if (event.getSource() == play)
if (current != null)
current.play();
}
}//
cheers for taking the time to help bz it is much appreciated.
Message was edited by:
fowlergod09
Message was edited by:
fowlergod09
looks good but I do not think you need the choiceListener, (I think you jst copied and pasted this code from your other program that does the same ;D)
i would suggest to implement ActionListener at the top of class JJJB
public class JJJB extends Applet implements ItemListener, ActionListener
and just add this method
public void actionPerformed (ActionEvent event){
if (current != null)
{
current.stop();
}
if (event.getSource() == play)
{
if (current != null)
{
current.play();
}
}
}
somewhere in the code.
Message was edited by:
Bz_Unknown
i didn't cut the code from the other program bz it is part of the cut down version i was given with the assignment. The code which i was given is far too advanced for me and besides i do not understand it and at the end of the day is doing me no good at all.
the code you wrote last is only for the buttons isn't it what about the code to select the track from the choicebox that is why i thought of choicebox as the example we were given used a checkbox
Well in the code you gave in the beginning, it used a Choice.
I do not get what is your question now.
The one used to check if the item is changed in the Choice is
public void itemStateChanged(ItemEvent ie){
changeGenre();
}
private void changeGenre() //line 229
{
if(genre.getSelectedItem().equalsIgnoreCase("Rock")){
rockChoice.setVisible(true);
popChoice.setVisible(false);
}
if(genre.getSelectedItem().equalsIgnoreCase("Pop")){
rockChoice.setVisible(false);
popChoice.setVisible(true);
}
repaint();
}
}
The one for buttons is above
what does equalsIgnoreCase mean bz? in laymans terms please.and my previous question was: in the choicbox rock+pop there is a tracklist of music, how do i get the track the is selected to play?Message was edited by: fowlergod09
equals() and equalsIgnoreCase() are used to compare Strings. You cannot use == because == checks if the values refer to same memory location.
For example you cannot use
String a = "hello";
String b = "hello";
b == a <- will return false if you compare
you have to use
a.equalsIgnoreCase(b); or
a.equals(b) for strings and it will return true
EDIT
add the actionPerformed method that was in an earlier post to your code. After that assign actionlisteners to your buttons.
Message was edited by:
Bz_Unknown
i am getting the following message when i try to compile it applies to this: public void actionPerformed (ActionEvent event){illegal start of expression
> i am getting the following message when i try to
> compile it applies to this:
>
> public void actionPerformed (ActionEvent event){
>
> illegal start of expression
You've mucked up something else. The compiler is complaining because it isn't expecting a method to start where-ever you have that in your code. That means you have an extra { or } somewhere earlier.
this my code as i have it now:
/**
* @(#)JJJB.java
*
* JJJB Applet application
*
* @author
* @version 1.00 2007/1/4
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.applet.Applet;
import java.net.URL;
public class JJJB extends Applet implements ItemListener, ActionListener{
private Panel controlPanel,topPanel;
private Panel middPanel;
private Choice rockChoice,popChoice,genre;
private Button play,stop;
private String[] rocklist;
private String[] poplist;
private DrawingCanvas DrawingCanvas;
private AudioClip[]rockMusic;
private AudioClip[]popMusic;
private AudioClipcurrent;
private URL url1, url2, url3, url4, url5, url6, url7, url8, url9, url10,url11;
public void init() {
try
{
url1=new URL ("file", "localhost","song1.wav");
url2=new URL ("file", "localhost","song2.wav");
url3=new URL ("file", "localhost","song3.wav");
url4=new URL ("file", "localhost","song4.wav");
url5=new URL ("file", "localhost","song5.wav");
url6=new URL ("file", "localhost","song6.wav");
url7=new URL ("file", "localhost","song7.wav");
url8=new URL ("file", "localhost","song8.wav");
url9=new URL ("file", "localhost","song9.wav");
url10=new URL ("file", "localhost","song10.wav");
url11=new URL ("fil", "localhost","song11.wav");
}
catch(Exception exception)
{
}
//ARRAYS
rockMusic = new AudioClip[6];
rockMusic[0] = null;
rockMusic[1] = Applet.newAudioClip(url1);
rockMusic[2] = Applet.newAudioClip(url2);
rockMusic[3] = Applet.newAudioClip(url3);
rockMusic[4] = Applet.newAudioClip(url4);
rockMusic[5] = Applet.newAudioClip(url5);
//-
popMusic = new AudioClip[6];
popMusic[0] = null;
popMusic[1] = Applet.newAudioClip(url6);
popMusic[2] = Applet.newAudioClip(url7);
popMusic[3] = Applet.newAudioClip(url8);
popMusic[4] = Applet.newAudioClip(url9);
popMusic[5] = Applet.newAudioClip(url10);
setLayout(new BorderLayout());
controlPanel = new Panel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.blue);
stop = new Button("STOP");
stop.setBackground(Color.cyan);
stop.addActionListener(this);
play = new Button("PLAY");
play.setBackground(Color.cyan);
stop.addActionListener(this);
controlPanel.add(stop);
controlPanel.add(play);
add(controlPanel,"South");
rockChoice = new Choice();
popChoice = new Choice();
rocklist = new String[]{
"Select Rock Song","Turn up The Sun", "Mucky Fingers", "LYLA", "Love Like A Bomb", "A Bell Will Ring", "Let There BE Love" };
for (int i = 0; i < rocklist.length; i++)
rockChoice.add(rocklist[i]);
poplist = new String[]{
"Select Pop Song","The Meaning Of Soul", "Guess God Thinks I Am Able", "Part Of The Queue",
"Keep The Dream Alive" };
genre= new Choice();
genre.add("Rock");
genre.addItemListener(this);
genre.add("Pop");
genre.addItemListener(this);
for (int i = 0; i < poplist.length; i++)
popChoice.add(poplist[i]);
rockChoice.addItemListener(this);
popChoice.addItemListener(this);
DrawingCanvas drawingCanvas = new DrawingCanvas();
topPanel = new Panel();
topPanel.setLayout(new BorderLayout());
topPanel.setBackground(Color.black);
topPanel.add(drawingCanvas,"Center");
add(topPanel,"North");
rockChoice.setVisible(false);
popChoice.setVisible(true);
middPanel = new Panel();
middPanel.setLayout(new GridLayout(1,3,10,10));
middPanel.setBackground(Color.red);
middPanel.add(rockChoice);
middPanel.add(genre);
middPanel.add(popChoice);
add(middPanel,"Center");
}
private class DrawingCanvas extends Canvas{
private DrawingCanvas(){
setSize(100,200);
}
public void paint(Graphics g) {
g.drawString("Welcome to Java!!", 50, 60 );
}
}
public void itemStateChanged(ItemEvent ie){
if(genre.getSelectedItem().equals("Rock")){
rockChoice.setVisible(true);
popChoice.setVisible(false);
}
else if(genre.getSelectedItem().equals("Pop")){
popChoice.setVisible(true);
rockChoice.setVisible(false);
}
}
public void actionPerformed (ActionEvent e)
{
if (current != null)
current.stop();
Choicekbox chk = genreChoice.getSelectedCheckbox();
if(chk.getLabel()=="Rock")
current = RockMusic[rockChoice.getSelectedIndex()];
else if (chk.getLabel()=="Pop")
current = PopMusic[popChoice.getSelectedIndex()];
public void actionPerformed (ActionEvent event){
if (current != null)
{
current.stop();
}
if (event.getSource() == play)
{
if (current != null)
{
current.play();
}
}
this should play music try it.
i even added comments at the important parts.
/**
* @(#)JJJB.java
*
* JJJB Applet application
*
* @author
* @version 1.00 2007/1/4
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.applet.Applet;
import java.net.URL;
public class JJJB extends Applet implements ItemListener, ActionListener{
private Panel controlPanel,topPanel;
private Panel middPanel;
private Choice rockChoice,popChoice,genre;
private Button play,stop;
private String[] rocklist;
private String[] poplist;
private DrawingCanvas DrawingCanvas;
private AudioClip[]rockMusic;
private AudioClip[]popMusic;
private AudioClipcurrent;
private URL url1, url2, url3, url4, url5, url6, url7, url8, url9, url10,url11;
public void init() {
try
{
url1=new URL ("file", "localhost","song1.wav");
url2=new URL ("file", "localhost","song2.wav");
url3=new URL ("file", "localhost","song3.wav");
url4=new URL ("file", "localhost","song4.wav");
url5=new URL ("file", "localhost","song5.wav");
url6=new URL ("file", "localhost","song6.wav");
url7=new URL ("file", "localhost","song7.wav");
url8=new URL ("file", "localhost","song8.wav");
url9=new URL ("file", "localhost","song9.wav");
url10=new URL ("file", "localhost","song10.wav");
url11=new URL ("fil", "localhost","song11.wav");
}
catch(Exception exception)
{
}
//ARRAYS
rockMusic = new AudioClip[6];
rockMusic[0] = null;
rockMusic[1] = Applet.newAudioClip(url1);
rockMusic[2] = Applet.newAudioClip(url2);
rockMusic[3] = Applet.newAudioClip(url3);
rockMusic[4] = Applet.newAudioClip(url4);
rockMusic[5] = Applet.newAudioClip(url5);
//-
popMusic = new AudioClip[6];
popMusic[0] = null;
popMusic[1] = Applet.newAudioClip(url6);
popMusic[2] = Applet.newAudioClip(url7);
popMusic[3] = Applet.newAudioClip(url8);
popMusic[4] = Applet.newAudioClip(url9);
popMusic[5] = Applet.newAudioClip(url10);
setLayout(new BorderLayout());
controlPanel = new Panel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.blue);
stop = new Button("STOP");
stop.setBackground(Color.cyan);
stop.addActionListener(this); //register an action listener to the button
play = new Button("PLAY");
play.setBackground(Color.cyan);
play.addActionListener(this); //register an action listener to the button
controlPanel.add(stop);
controlPanel.add(play);
add(controlPanel,"South");
rockChoice = new Choice();
popChoice = new Choice();
rocklist = new String[]{
"Select Rock Song","Turn up The Sun", "Mucky Fingers", "LYLA", "Love Like A Bomb", "A Bell Will Ring", "Let There BE Love" };
for (int i = 0; i < rocklist.length; i++)
rockChoice.add(rocklist[i]);
poplist = new String[]{
"Select Pop Song","The Meaning Of Soul", "Guess God Thinks I Am Able", "Part Of The Queue",
"Keep The Dream Alive" };
genre= new Choice();
genre.add("Rock");
genre.add("Pop");
genre.addItemListener(this); //registers an itemlistener to the genre choice
for (int i = 0; i < poplist.length; i++)
popChoice.add(poplist[i]);
rockChoice.addItemListener(this);
popChoice.addItemListener(this);
DrawingCanvas drawingCanvas = new DrawingCanvas();
topPanel = new Panel();
topPanel.setLayout(new BorderLayout());
topPanel.setBackground(Color.black);
topPanel.add(drawingCanvas,"Center");
add(topPanel,"North");
middPanel = new Panel();
middPanel.setLayout(new FlowLayout());
middPanel.setBackground(Color.red);
middPanel.add(genre);
middPanel.add(rockChoice);
middPanel.add(popChoice);
add(middPanel,"Center");
//changeGenre();
}
private class DrawingCanvas extends Canvas{
private DrawingCanvas(){
setSize(100,200);
}
public void paint(Graphics g) {
g.drawString("Welcome to Java!!", 50, 60 );
}
}
public void itemStateChanged(ItemEvent ie)
{
if (ie.getSource() == genre) // if action is in the genre choice it changes genre
changeGenre();
if (ie.getSource() == rockChoice) // if action is in rockchoice it sets the rock song
current = rockMusic[rockChoice.getSelectedIndex()];
if (ie.getSource() == popChoice) // if action is in popchoice it sets the pop song
current = popMusic[popChoice.getSelectedIndex()];
}
private void changeGenre() //line 229
{
if(genre.getSelectedItem().equalsIgnoreCase("Rock")){
rockChoice.setVisible(true);
popChoice.setVisible(false);
}
if(genre.getSelectedItem().equalsIgnoreCase("Pop")){
rockChoice.setVisible(false);
popChoice.setVisible(true);
}
repaint();
}
// actionPerformed is called when a button is clicked
public void actionPerformed (ActionEvent event)
{
if (event.getSource() == stop) // if button stop is clicked
{
if (current != null) // checks if null
{
current.stop(); // stops the sound
}
}
if (event.getSource() == play)
{
if (current != null)
{
current.play();
}
}
}
}
I see.
Well that starts off okay and then ends badly.
You can't do that. You need to put that second action performed in another class or merge them into one. Your choice. But you can't have two identical methods in the same class and you can't stick one inside another (as you appear to be doing).
bz you are too good, i will study this code and try to lean from it. can inow create graphics on the drawing canvas, that is one thing i have done correctly i hope>
use Graphics to draw images
Heres how to add an image to your project
public void paintComponent(Graphics g)
{
super.paintComponent(g);
ImageIcon picture = new ImageIcon("picture.jpg");
Image pictureImage = picture.getImage();
g.drawImage(pictureImage, x, y, this);
}
x,y are x,y coordinated on the window
i have to give a demonstration of my project on monday at uni. I have no idea about that last code you gave me and when i was asked questions on it i would lokk even more stupid than i am. But thanks bz you have been a massive help.Can i asked you what it was you did to make it work as apposed to what i had done, i cannot compare now as i cut & pasted in your code.
well i added some comments in it...
and i have to go now, email me jzh001@gmail.com, and I'll go into more detail of what I did.
-Bz
Lets see if i can quickly sum up what i did. In the item listener class, i set it that it changes genre only if the action happens from the genre. If the user changes songs in a rock or pop choice, it will send an event as well to the item listener class. If it does, I just set current (the audioclip) to the choice of either rock music or pop music. I do that by getting the index of the item they selected (which is actually the song) and setting current = rockMusic[rockMusic.getSelectedGenre()] and same for pop except I change the rockMusic to popMusic...
If you still have more questions, see my first paragraph in this post
thanks mate for all your help, i will email you as i am really struggling with java as you may have guessed.take careglenn
> looks good but I do not think you need the
> choiceListener, (I think you jst copied and pasted
> this code from your other program that does the same
> ;D)
>
> i would suggest to implement ActionListener at the
> top of class JJJB
> > public class JJJB extends Applet implements
> ItemListener, ActionListener
>
Actually, he would be better off putting the ItemListener and ActionListener as inner classes as he had, rather than making the whole class be the ItemListener and ActionListener. Especially if different Components in the class need different actions.