Hi, i am just about out of time to produce a working jukebox which has to perform these functions: to play music files when a track is chosen from a list which when the user presses the change genre button the list is populated with a list of that genre.
I have got the interface done to satisfaction, my problem is that when i press the change genre button nothing happens and when i select a track to play from the list which is setvisible and press the play button nothing happens. I have been at this now for the last 28 hours without a break and i really do not know what else to do.
my operating system is xp pro, i use jcreator v4 as my compiler.
here is my code i would be very grateful if anyone can help me, i must add i have only been programming for 3 months so forgive me if i have posted incorrectly
/ - * @(#)Help.java
-
*
-
* Help application
-
*
-
* @author
-
* @version 1.00 2006/12/30
-
*/
-
import java.applet.Applet;
-
import java.applet.AudioClip;
-
import java.awt.BorderLayout;
-
import java.awt.Button;
-
import java.awt.Canvas;
-
import java.awt.Checkbox;
-
import java.awt.CheckboxGroup;
-
import java.awt.Color;
-
import java.awt.FlowLayout;
-
import java.awt.Font;
-
import java.awt.Frame;
-
import java.awt.Graphics;
-
import java.awt.List;
-
import java.awt.Panel;
-
import java.awt.event.ActionEvent;
-
import java.awt.event.ActionListener;
-
import java.awt.event.WindowAdapter;
-
import java.awt.event.WindowEvent;
-
import java.net.URL;
-
public class Help extends Frame {
-
private Panel controlPanel;
-
private Panel drawPanel;
-
private Panel topPanel;
-
private Panel rPanel;
-
private CheckboxGroup genre;
-
private Checkbox rock;
-
private Checkbox pop;
-
private Button play;
-
private Button stop;
-
private Button changegenre;
-
private List rockChoice, popChoice;
-
private DrawingCanvas DrawingCanvas;
-
private String poplist[];
-
private String rocklist[];
-
private URL url1;
-
private URL url2;
-
private URL url3;
-
private URL url4;
-
private URL url5;
-
private URL url6;
-
private AudioClip[] rockMusic;
-
private URL url7;
-
private URL url8;
-
private URL url9;
-
private URL url10;
-
private URL url11;
-
private AudioClip[] popMusic;
-
private AudioClip current;
-
public Help()//costructor
-
{
-
rockMusic = new AudioClip[6];
-
try
-
{
-
rockMusic[0] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[1] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[2] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[3] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[4] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[5] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
}
-
catch (Exception exception) {}
-
popMusic = new AudioClip[5];
-
try
-
{
-
popMusic[0] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[1] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[2] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[3] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[4] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
}
-
catch (Exception ex) {}
-
setLayout(new BorderLayout());
-
drawPanel = new Panel();
-
drawPanel.setLayout(new BorderLayout());
-
drawPanel.setBackground(Color.black);
-
DrawingCanvas drawingCanvas = new DrawingCanvas();
-
drawPanel.add(drawingCanvas, "Center");
-
add(drawPanel, "North");
-
stop = new Button("STOP");
-
stop.setBackground(Color.blue);
-
play = new Button("PLAY");
-
play.setBackground(Color.blue);
-
changegenre = new Button("CHANGE GENRE");
-
changegenre.setBackground(Color.blue);
-
controlPanel = new Panel();
-
controlPanel.setBackground(Color.red);
-
controlPanel.setLayout(new FlowLayout());
-
controlPanel.add(play);
-
play.addActionListener(new ButtonListener());
-
controlPanel.add(stop);
-
stop.addActionListener(new ButtonListener());
-
controlPanel.add(changegenre);
-
changegenre.addActionListener(new ButtonListener());
-
add(controlPanel, "South");
-
genre = new CheckboxGroup();
-
rock = new Checkbox("ROCK", genre, true);
-
pop = new Checkbox("POP", genre, false);
-
topPanel = new Panel();
-
topPanel.setLayout(new FlowLayout());
-
topPanel.setBackground(Color.yellow);
-
topPanel.add(rock);
-
topPanel.add(pop);
-
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"
-
};
-
rockChoice = new List();
-
for (int i = 0; i < rocklist.length; i++)
-
rockChoice.add(rocklist[i]);
-
poplist = new String[]{"Select Pop Song","The Importance Of Being Idle","The Meaning Of Soul","Guess God Thinks I Am Able","Part Of TheQueue","Keep The Dream Alive"};
-
popChoice = new List();
-
for (int i = 0; i < poplist.length; i++)
-
popChoice.add(poplist[i]);
-
topPanel.add(rockChoice);
-
rockChoice.setVisible(true);
-
rockChoice.addActionListener(new ListListener());
-
topPanel.add(popChoice);
-
popChoice.setVisible(false);
-
popChoice.addActionListener(new ListListener());
-
add(topPanel, "Center");
-
addWindowListener(new WindowAdapter() {
-
public void windowClosing(WindowEvent e) {
-
dispose();
-
System.exit(0);
-
}
-
});
-
}
- public static void main(String[] args) {
-
Help mainFrame = new Help();
-
mainFrame.setSize(800, 600);
-
mainFrame.setTitle("Glenn's Java Jukebox");
-
mainFrame.setVisible(true);
-
}
- private class DrawingCanvas extends Canvas {
-
-
private DrawingCanvas() {
-
setSize(100, 400);
-
}
-
- public void paint(Graphics g) {
-
// do all the drawing of the jukebox in the
-
g.drawString("please work", 50, 50);
-
g.setColor(Color.yellow);
-
g.fillRect(700, 105, 30, 450);
-
g.fillRect(80, 105, 30, 450);
-
-
g.setColor(Color.yellow);
-
g.fillArc(80, 10, 650, 200, -180, -180);
-
g.setColor(Color.white);
-
g.fillOval(150, 60, 20, 20);
-
g.fillOval(210, 60, 20, 20);
-
g.fillOval(270, 60, 20, 20);
-
g.fillOval(330, 60, 20, 20);
-
g.fillOval(390, 60, 20, 20);
-
g.fillOval(630, 60, 20, 20);
-
g.fillOval(450, 60, 20, 20);
-
g.fillOval(510, 60, 20, 20);
-
g.fillOval(570, 60, 20, 20);
-
g.setColor(Color.black);
-
g.fillOval(180, 60, 20, 20);
-
g.fillOval(240, 60, 20, 20);
-
g.fillOval(300, 60, 20, 20);
-
g.fillOval(360, 60, 20, 20);
-
g.fillOval(420, 60, 20, 20);
-
g.fillOval(480, 60, 20, 20);
-
g.fillOval(540, 60, 20, 20);
-
g.fillOval(200, 80, 15, 15);
-
g.fillOval(380, 80, 15, 15);
-
g.fillOval(260, 80, 15, 15);
-
g.fillOval(320, 80, 15, 15);
-
g.fillOval(380, 80, 15, 15);
-
g.fillOval(440, 80, 15, 15);
-
g.fillOval(500, 80, 15, 15);
-
g.fillOval(560, 80, 15, 15);
-
g.fillOval(620, 80, 15, 15);
-
g.fillOval(680, 80, 15, 15);
-
g.fillOval(140, 80, 15, 15);
-
g.fillOval(600, 60, 20, 20);
-
g.fillOval(660, 60, 20, 20);
-
g.setColor(Color.red);
-
g.fillOval(110, 80, 15, 15);
-
g.fillOval(170, 80, 15, 15);
-
g.fillOval(230, 80, 15, 15);
-
g.fillOval(290, 80, 15, 15);
-
g.fillOval(350, 80, 15, 15);
-
g.fillOval(410, 80, 15, 15);
-
g.fillOval(470, 80, 15, 15);
-
g.fillOval(530, 80, 15, 15);
-
g.fillOval(590, 80, 15, 15);
-
g.fillOval(650, 80, 15, 15);
-
g.setColor(Color.white);
-
g.fillRect(110, 100, 600, 500);
-
g.setColor(Color.magenta);
-
g.setFont(new Font("TimesRoman", Font.ITALIC, 48));
-
g.drawString(" Swurlitzer Jukebox", 230, 160);
-
g.setColor(Color.black);
-
g.setFont(new Font("Helvetica", Font.PLAIN, 18));
-
g.drawString(" 1.50 For 4 Plays", 140, 380);
-
g.drawString("Please Select Your Genre", 400, 380);
-
g.setFont(new Font("Helvetica", Font.ITALIC, 18));
-
g.drawString("Glenn Proudly Presents", 290, 40);
-
g.setColor(Color.yellow);
-
g.fillRect(690,100,20,450);
-
}
-
}//end DrawingCanvas
- private class ListListener implements ActionListener {
-
-
public void actionPerformed(ActionEvent e) {
-
if (current != null)
-
current.stop();
-
Checkbox chk = genre.getSelectedCheckbox();
-
if ("rock".equals(chk.getLabel()))
-
current = rockMusic[rockChoice.getSelectedIndex()];
-
else if ("pop".equals(chk.getLabel()))
-
current = popMusic[popChoice.getSelectedIndex()]; //213x1
-
}
-
}
- private class ButtonListener implements ActionListener {
-
-
public void actionPerformed(ActionEvent event) {
-
if (current != null)
-
current.stop();
-
if (event.getSource() == play)
-
if (current != null)
-
current.play();
-
if (event.getSource() == changegenre)
-
changeGenre();
-
}
-
}//end ButtonListener
- private void changeGenre() //line 229
-
{
-
Checkbox c = genre.getSelectedCheckbox();
-
if (c.getLabel() == "rock") //line 232
-
{
-
popChoice.setVisible(false);
-
rockChoice.setVisible(true); //line235
-
} //236
-
else if (c.getLabel() == "pop") {
-
//etc for other genres..
-
repaint();
-
}//end changeGenre() //line 241
-
-
-
}
-
}
1 2091
added ItemListener for your ROCK and POP CheckBoxes
- if you select from the list, then click ROCK then PLAY it shows it is picking up an AppletAudioClip
think you listeners need a lot more sorting out but this may help get you started -
/* @(#)Help.java
-
*
-
* Help application
-
*
-
* @author
-
* @version 1.00 2006/12/30
-
*/
-
import java.applet.Applet;
-
import java.applet.AudioClip;
-
import java.awt.BorderLayout;
-
import java.awt.Button;
-
import java.awt.Canvas;
-
import java.awt.Checkbox;
-
import java.awt.CheckboxGroup;
-
import java.awt.Color;
-
import java.awt.FlowLayout;
-
import java.awt.Font;
-
import java.awt.Frame;
-
import java.awt.Graphics;
-
import java.awt.List;
-
import java.awt.Panel;
-
import java.awt.event.*;
-
import java.net.URL;
-
public class Help extends Frame {
-
private Panel controlPanel;
-
private Panel drawPanel;
-
private Panel topPanel;
-
private Panel rPanel;
-
private CheckboxGroup genre;
-
private Checkbox rock;
-
private Checkbox pop;
-
private Button play;
-
private Button stop;
-
private Button changegenre;
-
private List rockChoice, popChoice;
-
private DrawingCanvas DrawingCanvas;
-
private String poplist[];
-
private String rocklist[];
-
private URL url1;
-
private URL url2;
-
private URL url3;
-
private URL url4;
-
private URL url5;
-
private URL url6;
-
private AudioClip[] rockMusic;
-
private URL url7;
-
private URL url8;
-
private URL url9;
-
private URL url10;
-
private URL url11;
-
private AudioClip[] popMusic;
-
private AudioClip current;
-
public Help()//costructor
-
{
-
rockMusic = new AudioClip[6];
-
try
-
{
-
rockMusic[0] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[1] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[2] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[3] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[4] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
rockMusic[5] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
}
-
catch (Exception exception) {}
-
popMusic = new AudioClip[5];
-
try
-
{
-
popMusic[0] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[1] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[2] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[3] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
popMusic[4] = Applet.newAudioClip(new java.net.URL("file:song7.wav"));
-
}
-
catch (Exception ex) {}
-
setLayout(new BorderLayout());
-
drawPanel = new Panel();
-
drawPanel.setLayout(new BorderLayout());
-
drawPanel.setBackground(Color.black);
-
DrawingCanvas drawingCanvas = new DrawingCanvas();
-
drawPanel.add(drawingCanvas, "Center");
-
add(drawPanel, "North");
-
stop = new Button("STOP");
-
stop.setBackground(Color.blue);
-
play = new Button("PLAY");
-
play.setBackground(Color.blue);
-
changegenre = new Button("CHANGE GENRE");
-
changegenre.setBackground(Color.blue);
-
controlPanel = new Panel();
-
controlPanel.setBackground(Color.red);
-
controlPanel.setLayout(new FlowLayout());
-
controlPanel.add(play);
-
play.addActionListener(new ButtonListener());
-
controlPanel.add(stop);
-
stop.addActionListener(new ButtonListener());
-
controlPanel.add(changegenre);
-
changegenre.addActionListener(new ButtonListener());
-
add(controlPanel, "South");
-
genre = new CheckboxGroup();
-
rock = new Checkbox("ROCK", genre, false);
-
rock.addItemListener(new MyItemListener()); // *** added
-
pop = new Checkbox("POP", genre, true);
-
pop.addItemListener(new MyItemListener()); // *** added
-
topPanel = new Panel();
-
topPanel.setLayout(new FlowLayout());
-
topPanel.setBackground(Color.yellow);
-
topPanel.add(rock);
-
topPanel.add(pop);
-
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"
-
};
-
rockChoice = new List();
-
for (int i = 0; i < rocklist.length; i++)
-
rockChoice.add(rocklist[i]);
-
poplist = new String[]{"Select Pop Song","The Importance Of Being Idle","The Meaning Of Soul","Guess God Thinks I Am Able","Part Of TheQueue","Keep The Dream Alive"};
-
popChoice = new List();
-
for (int i = 0; i < poplist.length; i++)
-
popChoice.add(poplist[i]);
-
topPanel.add(rockChoice);
-
rockChoice.setVisible(true);
-
rockChoice.addActionListener(new ListListener());
-
topPanel.add(popChoice);
-
popChoice.setVisible(false);
-
popChoice.addActionListener(new ListListener());
-
add(topPanel, "Center");
-
addWindowListener(new WindowAdapter() {
-
public void windowClosing(WindowEvent e) {
-
dispose();
-
System.exit(0);
-
}
-
});
-
}
-
public static void main(String[] args) {
-
Help mainFrame = new Help();
-
mainFrame.setSize(800, 600);
-
mainFrame.setTitle("Glenn's Java Jukebox");
-
mainFrame.setVisible(true);
-
}
-
private class DrawingCanvas extends Canvas {
-
-
private DrawingCanvas() {
-
setSize(100, 400);
-
}
-
public void paint(Graphics g) {
-
// do all the drawing of the jukebox in the
-
g.drawString("please work", 50, 50);
-
g.setColor(Color.yellow);
-
g.fillRect(700, 105, 30, 450);
-
g.fillRect(80, 105, 30, 450);
-
-
g.setColor(Color.yellow);
-
g.fillArc(80, 10, 650, 200, -180, -180);
-
g.setColor(Color.white);
-
g.fillOval(150, 60, 20, 20);
-
g.fillOval(210, 60, 20, 20);
-
g.fillOval(270, 60, 20, 20);
-
g.fillOval(330, 60, 20, 20);
-
g.fillOval(390, 60, 20, 20);
-
g.fillOval(630, 60, 20, 20);
-
g.fillOval(450, 60, 20, 20);
-
g.fillOval(510, 60, 20, 20);
-
g.fillOval(570, 60, 20, 20);
-
g.setColor(Color.black);
-
g.fillOval(180, 60, 20, 20);
-
g.fillOval(240, 60, 20, 20);
-
g.fillOval(300, 60, 20, 20);
-
g.fillOval(360, 60, 20, 20);
-
g.fillOval(420, 60, 20, 20);
-
g.fillOval(480, 60, 20, 20);
-
g.fillOval(540, 60, 20, 20);
-
g.fillOval(200, 80, 15, 15);
-
g.fillOval(380, 80, 15, 15);
-
g.fillOval(260, 80, 15, 15);
-
g.fillOval(320, 80, 15, 15);
-
g.fillOval(380, 80, 15, 15);
-
g.fillOval(440, 80, 15, 15);
-
g.fillOval(500, 80, 15, 15);
-
g.fillOval(560, 80, 15, 15);
-
g.fillOval(620, 80, 15, 15);
-
g.fillOval(680, 80, 15, 15);
-
g.fillOval(140, 80, 15, 15);
-
g.fillOval(600, 60, 20, 20);
-
g.fillOval(660, 60, 20, 20);
-
g.setColor(Color.red);
-
g.fillOval(110, 80, 15, 15);
-
g.fillOval(170, 80, 15, 15);
-
g.fillOval(230, 80, 15, 15);
-
g.fillOval(290, 80, 15, 15);
-
g.fillOval(350, 80, 15, 15);
-
g.fillOval(410, 80, 15, 15);
-
g.fillOval(470, 80, 15, 15);
-
g.fillOval(530, 80, 15, 15);
-
g.fillOval(590, 80, 15, 15);
-
g.fillOval(650, 80, 15, 15);
-
g.setColor(Color.white);
-
g.fillRect(110, 100, 600, 500);
-
g.setColor(Color.magenta);
-
g.setFont(new Font("TimesRoman", Font.ITALIC, 48));
-
g.drawString(" Swurlitzer Jukebox", 230, 160);
-
g.setColor(Color.black);
-
g.setFont(new Font("Helvetica", Font.PLAIN, 18));
-
g.drawString(" 1.50 For 4 Plays", 140, 380);
-
g.drawString("Please Select Your Genre", 400, 380);
-
g.setFont(new Font("Helvetica", Font.ITALIC, 18));
-
g.drawString("Glenn Proudly Presents", 290, 40);
-
g.setColor(Color.yellow);
-
g.fillRect(690,100,20,450);
-
}
-
}//end DrawingCanvas
-
private class ListListener implements ActionListener {
-
-
public void actionPerformed(ActionEvent e) {
-
System.out.println("ListListener ");
-
if (current != null)
-
current.stop();
-
Checkbox chk = genre.getSelectedCheckbox();
-
if ("rock".equals(chk.getLabel()))
-
current = rockMusic[rockChoice.getSelectedIndex()];
-
else if ("pop".equals(chk.getLabel()))
-
current = popMusic[popChoice.getSelectedIndex()]; //213x1
-
}
-
}
-
-
-
private class MyItemListener implements ItemListener { // **** added this
-
-
public void itemStateChanged(ItemEvent e) {
-
System.out.println("MyItemListener " + e);
-
if (current != null)
-
current.stop();
-
Checkbox chk = genre.getSelectedCheckbox();
-
System.out.println("checkbox " + chk + "\ncurrent " + current);
-
if ("ROCK".equals(chk.getLabel())) // ***
-
current = rockMusic[rockChoice.getSelectedIndex()];
-
else if ("POP".equals(chk.getLabel())) // ***
-
current = popMusic[popChoice.getSelectedIndex()]; //213x1
-
}
-
}
-
private class ButtonListener implements ActionListener {
-
-
public void actionPerformed(ActionEvent event) {
-
System.out.println("ButtonListener " + event + "\ncurrent " + current);
-
if (current != null)
-
current.stop();
-
if (event.getSource() == play)
-
if (current != null)
-
current.play();
-
if (event.getSource() == changegenre)
-
changeGenre();
-
}
-
}//end ButtonListener
-
private void changeGenre() //line 229
-
{
-
Checkbox c = genre.getSelectedCheckbox();
-
System.out.println("changeGenre()");
-
if (c.getLabel() == "rock") //line 232
-
{
-
popChoice.setVisible(false);
-
rockChoice.setVisible(true); //line235
-
} //236
-
else if (c.getLabel() == "pop") {
-
//etc for other genres..
-
repaint();
-
}//end changeGenre() //line 241
-
-
-
}
-
}
-
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
reply
views
Thread by abcd |
last post: by
|
2 posts
views
Thread by James |
last post: by
|
2 posts
views
Thread by newbievn |
last post: by
|
8 posts
views
Thread by kp87 |
last post: by
|
5 posts
views
Thread by skumar434 |
last post: by
|
reply
views
Thread by gunimpi |
last post: by
| |
8 posts
views
Thread by inFocus |
last post: by
| | | | | | | | | | | |