Hey guys for some reason my code displays in the applet viewer in jgrasp and in eclipse, but for some reason it wont display via an html file in any browser. Any Ideas? Thanks in advance.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class FamilyTreeTabbedPane extends JApplet implements ActionListener, MouseListener{
//Make buttons and labels local to the class so that they can be accessed by all methods, and the action performed method
JButton gButton, gTwoButton, gThreeButton,pButton, pTwoButton, pThreeButton,sButton, sTwoButton, sThreeButton,gPlay,gStop,pPlay,pStop,sPlay,sStop;
JLabel grandText, parentText, siblingText;
//create audio clips
AudioClip gac,pac,sac;
JTabbedPane tabPane;
public void init(){
//initialize my jtabbedpane
tabPane = new JTabbedPane();
//set up tabpane mouse listener to listen for when clicked event
tabPane.addMouseListener(this);
//set size of the applet
setSize(1400, 610);
//create a new tab with an icon and the appropriate returned panel
tabPane.addTab("Grandparent",new ImageIcon("grandIcon.jpg"), grandparentsTab());
tabPane.addTab("Parents",new ImageIcon("parentIcon.jpg"),parentTab());
tabPane.addTab("Siblings",new ImageIcon("siblingIcon.jpg"),siblingTab());
//set the color of the tabbed panels
tabPane.setBackgroundAt(0, Color.CYAN);
tabPane.setBackgroundAt(1, Color.GREEN);
tabPane.setBackgroundAt(2, Color.magenta);
//add tabPane to the applet
add(tabPane);
}
//I normally would not have created three different method names, It adds alot of tedious work that can easily be circumvented by overloading the same one
//but in the instructions it said create three seperate methods for each tab, and I wasn't sure if method overloading was allowed, so I played it safe.
public JPanel grandparentsTab(){
//create jpanel and Button
JPanel grand, borderFrame, audioPanel;
//setup audio clip
gac = getAudioClip( getCodeBase(),"make my dreams come true.wav");
//create jButtons
gButton = new JButton(new ImageIcon("Grandparent.jpg"));
gTwoButton = new JButton(new ImageIcon("Grandparent2.jpg"));
gThreeButton = new JButton(new ImageIcon("Grandparent3.jpg"));
gPlay = new JButton("Play");
gStop = new JButton("Stop");
//create jLabel
grandText = new JLabel(" ",JLabel.CENTER);
//create jpanels
grand = new JPanel();
audioPanel=new JPanel();
borderFrame = new JPanel(new BorderLayout());
//add action listeners
gButton.addActionListener(this);
gTwoButton.addActionListener(this);
gThreeButton.addActionListener(this);
gPlay.addActionListener(this);
gStop.addActionListener(this);
//add to panel
grand.add(gButton);
grand.add(gTwoButton);
grand.add(gThreeButton);
audioPanel.add(gPlay);
audioPanel.add(gStop);
//add items to borderFrame
borderFrame.add(grand,BorderLayout.CENTER);
borderFrame.add(grandText,BorderLayout.NORTH);
borderFrame.add(audioPanel,BorderLayout.SOUTH);
//return to panel
return borderFrame;
}
//refer to grandTab
public JPanel parentTab(){
JPanel parent, borderFrame, audioPanel;
pac = getAudioClip( getCodeBase(),"sweet disposition.wav");
pButton = new JButton(new ImageIcon("Parents.jpg"));
pTwoButton = new JButton(new ImageIcon("Parents2.jpg"));
pThreeButton = new JButton(new ImageIcon("Parents3.jpg"));
pPlay = new JButton("Play");
pStop = new JButton("Stop");
parentText = new JLabel(" ",JLabel.CENTER);
audioPanel=new JPanel();
parent = new JPanel();
borderFrame = new JPanel(new BorderLayout());
pButton.addActionListener(this);
pTwoButton.addActionListener(this);
pThreeButton.addActionListener(this);
pPlay.addActionListener(this);
pStop.addActionListener(this);
parent.add(pButton);
parent.add(pTwoButton);
parent.add(pThreeButton);
audioPanel.add(pPlay);
audioPanel.add(pStop);
borderFrame.add(parent,BorderLayout.CENTER);
borderFrame.add(parentText,BorderLayout.NORTH);
borderFrame.add(audioPanel,BorderLayout.SOUTH);
return borderFrame;
}
//refer to grandTab
public JPanel siblingTab(){
JPanel sibling, borderFrame, audioPanel;
sac = getAudioClip( getCodeBase(),"shes got you high.wav");
sButton = new JButton(new ImageIcon("siblings.jpg"));
sTwoButton = new JButton(new ImageIcon("siblings2.jpg"));
sThreeButton = new JButton(new ImageIcon("siblings3.jpg"));
sPlay = new JButton("Play");
sStop = new JButton("Stop");
siblingText = new JLabel(" ",JLabel.CENTER);
audioPanel=new JPanel();
sibling = new JPanel();
borderFrame = new JPanel(new BorderLayout());
sButton.addActionListener(this);
sTwoButton.addActionListener(this);
sThreeButton.addActionListener(this);
sPlay.addActionListener(this);
sStop.addActionListener(this);
sibling.add(sButton);
sibling.add(sTwoButton);
sibling.add(sThreeButton);
audioPanel.add(sPlay);
audioPanel.add(sStop);
borderFrame.add(sibling,BorderLayout.CENTER);
borderFrame.add(siblingText,BorderLayout.NORTH);
borderFrame.add(audioPanel,BorderLayout.SOUTH);
return borderFrame;
}
public void actionPerformed(ActionEvent event) {
Object src = event.getSource();
if(src == gButton)
grandText.setText("This is my grandma!");
else if(src == gTwoButton)
grandText.setText("This is my grandma and my Family!");
else if(src == gThreeButton)
grandText.setText("This is my grandma and my mother!");
else if(src == pButton)
parentText.setText("My mom, dad, and my nephew!");
else if(src == pTwoButton)
parentText.setText("My mom and dad dancing!");
else if(src == pThreeButton)
parentText.setText("My mom and dad 80's style!");
else if(src == sButton)
siblingText.setText("Me my brother and my sister!");
else if(src == sTwoButton)
siblingText.setText("Wow was I young here!");
else if(src == sThreeButton)
siblingText.setText("Me and my sister!");
else if(src == gPlay){
stopMusic(sac);
stopMusic(pac);
gac.play();
}else if(src == gStop)
stopMusic(gac);
else if(src == pPlay){
stopMusic(gac);
stopMusic(sac);
pac.play();
}else if(src == pStop)
stopMusic(pac);
else if(src == sPlay){
stopMusic(gac);
stopMusic(pac);
sac.play();
}else if(src == sStop)
stopMusic(sac);
}
private void stopMusic(AudioClip clip){
//check if clip is playing if it is stop it
if(clip != null)
clip.stop();
}
public void mouseClicked(MouseEvent me)
{
int tabindex = tabPane.getSelectedIndex();
if (tabindex == 0)
{
gac.play();
pac.stop();
sac.stop();
}
else if (tabindex == 1)
{
pac.play();
gac.stop();
sac.stop();
}
else if (tabindex == 2)
{
sac.play();
gac.stop();
pac.stop();
}
}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
}
<html>
<head> <title>Thomas Stephen Brown</title></head>
<body><applet code="FamilyTreeTabbedPane.class" width="1400" height = "610"></applet></body>
</html>