Help with fun java Party planner applet that is not so much fun any more.

I am working on a code to produce a Java applet that will employ the use of a sound .wav file and images.  I  thought I was using the correct code, but already I am getting 12 errors - mostly on my .get and .set statements.  Here is what I have so far - I AM NOT ASKING FOR CODE, BUT DIRECTION IN WHERE I AM GOING WRONG.  I KNOW I'M A NEWBIE, BUT AN HONEST ONE THAT KEEPS FLIPPING BOOKS LOOKING FOR DIRECTION. -- Thank you!:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class JPartyPlannerTeamBcw1 extends JApplet implements ActionListener
{

private AudioClip sound;
Font bigFont = new Font("Helvetica", Font.BOLD, 24);
Font smallFont = new Font("TimesRoman", Font.ITALIC,14);
String header = new String ("Have you got an Event coming up?");
String title = new String ("Let us do the work so you can enjoy the party.");
String banner = new String("TEAM B PARTY PLANNERS INC");
String list =  new String ("invitations, supplies, decorations and more!");
JButton aboutUsBut = new JButton("About our Company");
JButton contactButton = new JButton("Contact us");
JButton partyButton = new JButton("Our Party Experts");

ImageIcon icon1 = new ImageIcon("rocket.gif");
ImageIcon icon2 = new ImageIcon("gift.gif");
ImageIcon icon3 = new ImageIcon("smallRocket.gif");
ImageIcon icon4 = new ImageIcon("starburst_multicolor.gif");

public void init()
{
sound = getAudioClip(getCodeBase(),"Celebration.wav");

Container con = getContentPane();
con.setBackground(Color.black);
con.setLayout(new FlowLayout());
banner.setFont(bigFont);
con.add(banner, 100,20);

header.setFont(smallFont);
con.add(header, 90,50);
list.setFont(smallFont);
con.add(list, 80,140);
con.add(icon4, 10,20);
con.add(icon4, 260,20);
con.add(icon2, 160,100);
con.add(aboutUsBut, 60,200);
aboutUsBut.addActionListener(this);
con.add(contactButton, 120,200);
contactButton.addActionListener(this);
con.add(partyButton,180,200);
partyButton.addActionListener(this);
}

public void actionPerformed(ActionEvent thisEvent)
{
      Graphics gr = getGraphics();
      Object source = thisEvent.getSource();
      if(source == aboutUsBut)
      gr.drawString("Team B Party Planning, Inc - established February 2006", 20,220);

      else if (source == contactButton)
      gr.drawString("Contact us at www.TeamBPartyPlan.com or 555.123.2323", 60,240);

      else if (source == partyButton)
      gr.drawString("Our expert team is comprised of Brent, Steve, Cyndy and Chad", 80,260);

}
}





cyndylove46Asked:
Who is Participating?
 
objectsCommented:
you can't set the font for a string.
nor add a string or image to your container.

you instead need to create JLabels and set the font for them and add the lable to your container
0
 
objectsCommented:
JLabel headerLabel = new JLabel(header);
headerLabel.setFont(smallFont);
con.add(headerLabel);
0
 
cyndylove46Author Commented:
Thank you "objects"..  I have taken another route to this code.  I felt I could better manipulate location and font attributes with the following code, however I am having a bear of a time adding sound and .gif files.  Ideas?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;

public class JPartyPlannerTeamBcwb extends JApplet
{
      private AudioClip sound;
      String companyName = new String("TEAM B PARTY PLANNERS INC.");
      String questionLine = new String("Have you got a special event coming up?");
      String offerLine = new String ("Let us do the work so you can ENJOY the party");
      String list = new String ("Location? Invitations? Decorations?  We do it all and a bit more!");
      Font bigFont = new Font("Helvetica", Font.BOLD, 24);
      Font midFont = new Font("Helvetica",Font.ITALIC, 14);
      Font smallFont = new Font("Helvetica", Font.PLAIN, 10);
      private ImageIcon partyLogo;
      JButton aboutUsBut = new JButton("About our Company");
      JButton contactButton = new JButton("Contact us");
      JButton partyButton = new JButton("Our Party Experts");

      public void init()
      {

      sound = getAudioClip(getCodeBase(),"Celebration.wav");
      partyLogo = new ImageIcon("starburst_multicolor.gif");
      Container con = getContentPane();
      con.setBackground(Color.darkGray);
      con.setLayout(new FlowLayout());

}



public void paint(Graphics gr)
{
      setBackground(Color.darkGray);
      gr.setFont(bigFont);
      gr.setColor(Color.cyan);
      gr.drawString(companyName, 60,100);
      gr.setFont(midFont);
      gr.setColor(Color.orange);
      gr.drawString(questionLine, 100,140);
      gr.setFont(midFont);
      gr.setColor(Color.orange);
      gr.drawString(offerLine, 80,160);
      gr.setFont(midFont);
      gr.setColor(Color.orange);
      gr.drawString(list, 40, 180);



}
}
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Manikandan ThiagarajanSenior consultantCommented:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class JPartyPlanner extends JApplet implements ActionListener
{

private AudioClip sound;
Font bigFont = new Font("Helvetica", Font.BOLD, 24);
Font smallFont = new Font("TimesRoman", Font.ITALIC,14);
String header = new String ("Have you got an Event coming up?");
String title = new String ("Let us do the work so you can enjoy the party.");
String banner = new String("TEAM B PARTY PLANNERS INC");
String list =  new String ("invitations, supplies, decorations and more!");
JButton aboutUsBut = new JButton("About our Company");
JButton contactButton = new JButton("Contact us");
JButton partyButton = new JButton("Our Party Experts");

ImageIcon icon1 = new ImageIcon("rocket.gif");
ImageIcon icon2 = new ImageIcon("gift.gif");
ImageIcon icon3 = new ImageIcon("smallRocket.gif");
ImageIcon icon4 = new ImageIcon("starburst_multicolor.gif");

public void init()
{
sound = getAudioClip(getCodeBase(),"Celebration.wav");

Container con = getContentPane();
con.setBackground(Color.black);
con.setLayout(new FlowLayout());
JLabel headerLabel = new JLabel(header);
headerLabel.setFont(smallFont);
con.add(headerLabel);

JLabel title1 = new JLabel(title);
headerLabel.setFont(smallFont);
con.add(title1);

JLabel banner1 = new JLabel(banner);
headerLabel.setFont(bigFont);
con.add(banner1);

JLabel list1 = new JLabel(banner);
headerLabel.setFont(smallFont);
con.add(list1);
//banner.setFont(bigFont);
//con.add(banner, 100,20);

//header.setFont(smallFont);
//con.add(header, 90,50);
//list.setFont(smallFont);
//con.add(list, 80,140);
//con.add(icon4, 10,20);
//con.add(icon4, 260,20);
//con.add(icon2, 160,100);
con.add(aboutUsBut);
aboutUsBut.addActionListener(this);
con.add(contactButton);
contactButton.addActionListener(this);
con.add(partyButton);
partyButton.addActionListener(this);
}

public void actionPerformed(ActionEvent thisEvent)
{
     Graphics gr = getGraphics();
     Object source = thisEvent.getSource();
     if(source == aboutUsBut)
     gr.drawString("Team B Party Planning, Inc - established February 2006", 20,220);

     else if (source == contactButton)
     gr.drawString("Contact us at www.TeamBPartyPlan.com or 555.123.2323", 60,240);

     else if (source == partyButton)
     gr.drawString("Our expert team is comprised of Brent, Steve, Cyndy and Chad", 80,260);

}
}




0
 
Manikandan ThiagarajanSenior consultantCommented:
try that code but  drawing part you havet to put in paint method
0
 
Manikandan ThiagarajanSenior consultantCommented:
could you tell me your exact problem now. if(source == aboutUsBut)

{

repaint();

}
 here you call the repaint method that would call the public void paint method
0
 
cyndylove46Author Commented:
I have it running now...THANK YOU ALL.  I am still stuck on the music file.  I gut a nullpointer error when I try to direct the program to use the .wav file.  It will compile, but not run the applet or use the .wav.  I downloaded the wav from a free online spot and saved it to the folder that contains my java program and the HTML applet file, but I wonder if there are security tags I am unaware of that halts the use of the .wav file?

I won't give up.  I feel I am close to an answer.  
0
 
objectsCommented:
where is the audio file? it should be in the same directory as the class files
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.