The Artima Developer Community
Sponsored Link

Java Answers Forum
help with drawing canvas please

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
glenn philipson

Posts: 1
Nickname: fowlergod0
Registered: Dec, 2006

help with drawing canvas please Posted: Dec 30, 2006 9:41 AM
Reply to this message Reply
Advertisement
I am very new to programming(3months) i have been given a task to create a jukebox which when tracks are selected or buttons are pressed then music should play. I Have drawn the jukebox and when i compile the program and execute it it displays all the panel and buttons ok but the drawing canvas on which i have drawn some graphics is not being displayed. I think that somehow it is being covered by the panels but after trying for hours to find a solution i have hit a brick wall.I am dreading adding the palylists and trying to get it to play songs.
could someone please look at my code and explain where and why i have gone wrong.

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();

}


}


i hope that this is the way to post code.please forgive me if not.
thanks glenn

Topic: help with drawing canvas please Previous Topic   Next Topic Topic: An Exception occur in my SQL

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use