PDA

View Full Version : help with drawing canvas please


fowlergod09
12-30-2006, 03:45 PM
i have to create a working jukebox that plays .wav files when the user interracts with the interface. I have created the design for the frame and when i compile and execute the program it works except that the graphics that i have created are not being displayed. I suspect that the panels are covering the drawing canvas but after a couple of days of trying i cannot get the drawing canvas to display my graphics. God only knows how i am going to cope when i have to add action listeners.
here is my code if anyone is kind enough to help

import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics.*;

class AssignmentJukebox extends Frame
{
TextArea tf;
Panel tPanel,rPanel,lPanel,bPanel,mPanel;
Button play,stop,swapgenre;
CheckboxGroup cb1;
Checkbox rock,pop;
List tracklist;
Scrollbar sBar;
Canvas canvas;
String[] popsongs[],rocksong[];

public AssignmentJukebox()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});

this.setSize(700,600);
this.setTitle("AssignmentJukebox");
setLayout(new BorderLayout());
tPanel = new Panel();
tPanel.setBackground(Color.red);
bPanel=new Panel();
bPanel.setBackground(Color.red);
bPanel.setLayout(new FlowLayout());
play=new Button("PLAY");
play.setBackground(Color.yellow);
stop=new Button("STOP");
stop.setBackground(Color.yellow);
swapgenre=new Button("Change Genre");
swapgenre.setBackground(Color.yellow);
bPanel.add(play);
bPanel.add(stop);
bPanel.add(swapgenre);
cb1=new CheckboxGroup();
rock=new Checkbox("ROCK",cb1,true);
pop=new Checkbox("POP",cb1,false);
lPanel=new Panel();
lPanel.setBackground(Color.red);
lPanel.setLayout(new FlowLayout());
lPanel.add(rock,"Center");
lPanel.add(pop,"South");
tracklist=new List();
tracklist.setBackground(Color.red);
tracklist.add("Please Select");
rPanel=new Panel();
rPanel.setBackground(Color.red);
rPanel.setLayout(new BorderLayout());
rPanel.add(tracklist,"South");
mPanel=new Panel();
DrawingCanvas drawingcanvas=new DrawingCanvas();
drawingcanvas.setBackground(Color.white);
mPanel.add("Center",drawingcanvas);
add("Center",mPanel);
add(rPanel,"West");
add(lPanel,"East");
add(bPanel,"South");
add(tPanel,"North");


}


public static void main(String args[])
{

System.out.println("AssignmentJukebox...");
AssignmentJukebox mainFrame = new AssignmentJukebox();
mainFrame.setVisible(true);


}

public class DrawingCanvas extends Canvas
{
private DrawingCanvas()

{
setSize(225,330);

}
}
public void paint(Graphics g)

{

g.setColor(Color.blue);

g.setFont(new Font("TimesRoman", Font.ITALIC, 28));

g.drawString("Glenn's Wurlitzer Jukebox", 240, 290);
g.setFont(new Font("Helvetica", Font.PLAIN, 12));
g.drawString("This is an example of plain 12pt Helvetica font", 20, 70);

g.setFont(new Font("TimesRoman", Font.PLAIN, 12));

g.drawString("This is an example of plain 12pt TimesRoman font", 20, 90);

super.paint(g);
g.setColor(Color.black);
g.drawArc(200,40,405,517,-180,-180);
g.drawRect(200,300,406,422);
g.setColor(Color.black);
g.fillOval(250,220,20,20);
g.fillOval(300,190,20,20);
repaint();

}
}