- Joined
- May 17, 2003
- Location
- England-Leeds
I am making a java application which is supposed to be a juke box that plays music. Also it needs to have radio buttons to choose a genre which in turn decides what list of music you can choose from. The problem is that I cant add the ButtonGroup to any of the panels in my GUI. In the code below ignore all the methods about playing files and stuff, thats not finished yet obviously. The problem is in the "add" method used to add the ButtonGroup somewhere. This is the code anyway:
And this is the error:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.sound.sampled.*;
import java.io.*;
import java.util.*;
class JboxApplication1 extends JFrame //implements LineListener, ActionListener
{
private JButton PlayBut;
private JButton StopBut;
private JRadioButton Metal, Noises, Rock;
private ButtonGroup GenreGroup;
private DrawingArea canvas;
private Container c;
private JPanel Genre;
private JPanel control;
public JboxApplication1(int width, int height)
{
c = getContentPane();
setSize(width, height);
c.setLayout(new BorderLayout());
canvas = new DrawingArea("Dummy file name");
Genre = new JPanel(new FlowLayout());
control = new JPanel(new FlowLayout());
ButtonGroup GenreGroup = new ButtonGroup();
PlayBut = new JButton("Play");
StopBut = new JButton("Stop");
Metal = new JRadioButton("Metal");
Noises = new JRadioButton("Kung fu Noises");
Rock = new JRadioButton("Rock");
GenreGroup.add(Metal);
GenreGroup.add(Noises);
GenreGroup.add(Rock);
Genre.add(GenreGroup);
control.add(PlayBut);
control.add(StopBut);
c.add("Center", canvas);
c.add("North",Genre);
c.add("South", control);
}
public void play(String fileName)
{
Clip clip = getClip(fileName);
if (clip != null)
{
clip.start();
System.out.println("Now Playing");
}
else
{
System.out.println("clip == null");
}
}
public Clip getClip(String fileName)
{
File f = new File(fileName);
Clip clip = null;
AudioInputStream ais = null;
try
{
ais = AudioSystem.getAudioInputStream(f);
clip = (Clip)AudioSystem.getLine(new Line.Info(Clip.class));
clip.open(ais);
//clip.addLineListener(this);
}
catch (UnsupportedAudioFileException uafe)
{
throw new RuntimeException("Unsupported type of audio file:\"" + fileName +"\"");
}
catch (LineUnavailableException lue)
{
throw new RuntimeException("Line unavailable to play sound\"" + fileName + "\"");
}
catch (IOException ioe)
{
throw new RuntimeException("I/O Error while reading file \"" + fileName + "\"");
}
return clip;
}
public static void main(String args[])
{
System.out.println("Starting JukeBox....");
JboxApplication1 myJB = new JboxApplication1(600, 500);
myJB.setVisible( true );
}
class DrawingArea extends Canvas
{
String fileName;
public DrawingArea(String fn)
{
fileName = fn;
}
public void paint(Graphics g)
{
g.drawString("Now playing " + fileName, 20, 20);
}
}
}
And this is the error:
Any help at all is much appreciated, the thing needs to be in by Friday so im kind of crapping myself.symbol : method add (javax.swing.ButtonGroup)
location: class javax.swing.JPanel
Genre.add(GenreGroup);
^
1 error