davidwarkasing
New member
ya well yesterday i posted a question and i still couldnt figure it out my problem is that everything works
the sound works and pop-up jframe works its just that the image wont load plz i need help heres the program and also if theres answers can u plz tell where u place them
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class Poke extends JApplet{
private JPanel ControlPanel;
private Image image;
private JButton playButton1;//playbutton for all the sounds
private JButton playButton;
private JButton playButton2;
private JButton playButton3;
private JLabel credit1;//labels
private JLabel credit;
private JLabel credit2;
private JButton stopButton1;//stopbutton for all the sounds
private JButton stopButton;
private JButton stopButton2;
private JButton stopButton3;
private AudioClip sound; // Holds the sound clip
private AudioClip sound1; // Holds the sound clip
private AudioClip sound2;
private AudioClip sound3;
public void init(){
setLayout(new FlowLayout());
credit = new JLabel("Can't");
add(credit);
credit1 = new JLabel("Touch");
add(credit1);
credit2 = new JLabel("Me");
add(credit2);
makeButtons();
sound = getAudioClip(getDocumentBase(), "Cantsound.wav");//Cant
sound1 = getAudioClip(getDocumentBase(), "Touchsound.wav");//touch
sound2 = getAudioClip(getDocumentBase(), "Mesound.wav");//me
sound3 = getAudioClip(getDocumentBase(), "Guy.wav");//fullsound
}
private void makeButtons()
{
playButton = new JButton("Play");
stopButton = new JButton("Stop");
playButton1 = new JButton("Play");
stopButton1 = new JButton("Stop");
playButton2 = new JButton("Play");
stopButton2 = new JButton("Stop");
playButton3 = new JButton("Play");
stopButton3 = new JButton("Stop");
playButton.addActionListener(new ButtonListener());
playButton1.addActionListener(new ButtonListener());
playButton2.addActionListener(new ButtonListener());
playButton3.addActionListener(new ButtonListener());
stopButton.addActionListener(new ButtonListener());
stopButton1.addActionListener(new ButtonListener());
stopButton2.addActionListener(new ButtonListener());
stopButton3.addActionListener(new ButtonListener());
add(playButton);
add(stopButton);
add(playButton1);
add(stopButton1);
add(playButton2);
add(stopButton2);
add(playButton3);
add(stopButton3);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == playButton)
sound.play();
else if (e.getSource() == stopButton)
sound.stop();
if (e.getSource() == playButton1)
sound1.play();
else if (e.getSource() == stopButton1)
sound1.stop();
if (e.getSource() == playButton2)
sound2.play();
else if (e.getSource() == stopButton2)
sound2.stop();
if (e.getSource() == playButton3)
sound3.play();
else if (e.getSource() == stopButton3)
sound3.stop();
image = getImage(getDocumentBase(), "Davi.gif");
JLabel label = new JLabel("");
label.setSize(400,25);
getContentPane().add(label, BorderLayout.NORTH);
JPanel ControlPanel = new JPanel();
ControlPanel.setSize(400,150);
getContentPane().add(ControlPanel, BorderLayout.SOUTH);
JFrame d = new JFrame("Final Project YAY");
;
image = getImage(getDocumentBase(), "body.gif");
d.setSize(400,400);
d.setVisible(true);
}
public void paint(Graphics g){
g.drawImage(image,500,200,ControlPanel);
}
public void update(Graphics g){
paint(g);
}
}
}
the sound works and pop-up jframe works its just that the image wont load plz i need help heres the program and also if theres answers can u plz tell where u place them
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
public class Poke extends JApplet{
private JPanel ControlPanel;
private Image image;
private JButton playButton1;//playbutton for all the sounds
private JButton playButton;
private JButton playButton2;
private JButton playButton3;
private JLabel credit1;//labels
private JLabel credit;
private JLabel credit2;
private JButton stopButton1;//stopbutton for all the sounds
private JButton stopButton;
private JButton stopButton2;
private JButton stopButton3;
private AudioClip sound; // Holds the sound clip
private AudioClip sound1; // Holds the sound clip
private AudioClip sound2;
private AudioClip sound3;
public void init(){
setLayout(new FlowLayout());
credit = new JLabel("Can't");
add(credit);
credit1 = new JLabel("Touch");
add(credit1);
credit2 = new JLabel("Me");
add(credit2);
makeButtons();
sound = getAudioClip(getDocumentBase(), "Cantsound.wav");//Cant
sound1 = getAudioClip(getDocumentBase(), "Touchsound.wav");//touch
sound2 = getAudioClip(getDocumentBase(), "Mesound.wav");//me
sound3 = getAudioClip(getDocumentBase(), "Guy.wav");//fullsound
}
private void makeButtons()
{
playButton = new JButton("Play");
stopButton = new JButton("Stop");
playButton1 = new JButton("Play");
stopButton1 = new JButton("Stop");
playButton2 = new JButton("Play");
stopButton2 = new JButton("Stop");
playButton3 = new JButton("Play");
stopButton3 = new JButton("Stop");
playButton.addActionListener(new ButtonListener());
playButton1.addActionListener(new ButtonListener());
playButton2.addActionListener(new ButtonListener());
playButton3.addActionListener(new ButtonListener());
stopButton.addActionListener(new ButtonListener());
stopButton1.addActionListener(new ButtonListener());
stopButton2.addActionListener(new ButtonListener());
stopButton3.addActionListener(new ButtonListener());
add(playButton);
add(stopButton);
add(playButton1);
add(stopButton1);
add(playButton2);
add(stopButton2);
add(playButton3);
add(stopButton3);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == playButton)
sound.play();
else if (e.getSource() == stopButton)
sound.stop();
if (e.getSource() == playButton1)
sound1.play();
else if (e.getSource() == stopButton1)
sound1.stop();
if (e.getSource() == playButton2)
sound2.play();
else if (e.getSource() == stopButton2)
sound2.stop();
if (e.getSource() == playButton3)
sound3.play();
else if (e.getSource() == stopButton3)
sound3.stop();
image = getImage(getDocumentBase(), "Davi.gif");
JLabel label = new JLabel("");
label.setSize(400,25);
getContentPane().add(label, BorderLayout.NORTH);
JPanel ControlPanel = new JPanel();
ControlPanel.setSize(400,150);
getContentPane().add(ControlPanel, BorderLayout.SOUTH);
JFrame d = new JFrame("Final Project YAY");
;
image = getImage(getDocumentBase(), "body.gif");
d.setSize(400,400);
d.setVisible(true);
}
public void paint(Graphics g){
g.drawImage(image,500,200,ControlPanel);
}
public void update(Graphics g){
paint(g);
}
}
}