Andrew Hoffman

Greenhorn
+ Follow
since Apr 30, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Andrew Hoffman

Sorry for the frantic subject line, but i have two short hours left before I am flushed down the perverbial toilet.
This applet plays a few audio clips. I need it to run as an applicaton, too. I don't know how to do that. Can someone be my hero and adjust the code acordingly? Thank You.
Andrew
***
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import Chapter8.MyFrameWithExitHandling;
import java.net.URL;
import java.applet.*;
public class Lab14_1 extends JApplet implements ActionListener
{
// Delcare Audio Files
protected AudioClip playAudio;
protected AudioClip loopAudio;
protected AudioClip stopAudio;
// Declare Buttons
private static JButton jplay = new JButton("PLAY");
private static JButton jloop = new JButton("LOOP");
private static JButton jstop = new JButton("STOP");
public void init()
{
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(jplay);
p.add(jloop);
p.add(jstop);
getContentPane().add(p);
// Register Listeners
jplay.addActionListener(this);
jloop.addActionListener(this);
jstop.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
// Get the file name
String filename = null;
if (e.getSource() == jplay)
filename = "Chapter14/Chimp.wav";
else if (e.getSource() == jloop)
filename = "Chaper14/Chimp.wav";
if
{
playAudio.stop();
loopAudio.loop();
}
if (e.getSource() == jstop)
{
playAudio.stop();
loopAudio.stop();
}
createClip(filename).play();
}
public AudioClip createClip(String filename)
{
// Get the URL for the file name
URL url = this.getClass().getResource("Chimp/" + filename);
// Return the audio clip
return Applet.newAudioClip(url);
}
public static void main(String [] args)
{
// Create a frame
MyFrameWithExitHandling frame = new MyFrameWithExitHandling(
"Lab14_1 Application");
// Crate an instance of the applet
Lab14_1 applet = new Lab14_1();
// Add applet to the fray
frame.getContentPane().add(applet, BorderLayout.CENTER);
// Invoke init() and start()
applet.init();
applet.start();
// Display the frame
frame.pack();
frame.center();
frame.setVisible(true);
}
}
23 years ago
Sorry for the frantic subject line, but i have two short hours left before I am flushed down the perverbial toilet.
This applet plays a few audio clips. I need it to run as an applicaton, too. I don't know how to do that. Can someone be my hero and adjust the code acordingly? Thank You.
Andrew
***
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import Chapter8.MyFrameWithExitHandling;
import java.net.URL;
import java.applet.*;
public class Lab14_1 extends JApplet implements ActionListener
{
// Delcare Audio Files
protected AudioClip playAudio;
protected AudioClip loopAudio;
protected AudioClip stopAudio;
// Declare Buttons
private static JButton jplay = new JButton("PLAY");
private static JButton jloop = new JButton("LOOP");
private static JButton jstop = new JButton("STOP");
public void init()
{
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(jplay);
p.add(jloop);
p.add(jstop);
getContentPane().add(p);
// Register Listeners
jplay.addActionListener(this);
jloop.addActionListener(this);
jstop.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
// Get the file name
String filename = null;
if (e.getSource() == jplay)
filename = "Chapter14/Chimp.wav";
else if (e.getSource() == jloop)
filename = "Chaper14/Chimp.wav";
if
{
playAudio.stop();
loopAudio.loop();
}
if (e.getSource() == jstop)
{
playAudio.stop();
loopAudio.stop();
}
createClip(filename).play();
}
public AudioClip createClip(String filename)
{
// Get the URL for the file name
URL url = this.getClass().getResource("Chimp/" + filename);
// Return the audio clip
return Applet.newAudioClip(url);
}
public static void main(String [] args)
{
// Create a frame
MyFrameWithExitHandling frame = new MyFrameWithExitHandling(
"Lab14_1 Application");
// Crate an instance of the applet
Lab14_1 applet = new Lab14_1();
// Add applet to the fray
frame.getContentPane().add(applet, BorderLayout.CENTER);
// Invoke init() and start()
applet.init();
applet.start();
// Display the frame
frame.pack();
frame.center();
frame.setVisible(true);
}
}
23 years ago
This runs as an applet but not an application. I need it to do both. Any help would be great.
import java.applet.*;
import java.awt.BorderLayout;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import Chapter8.MyFrameWithExitHandling;
public class Lab14_1 extends JApplet implements ActionListener
{
// Delcare Audio Files
static AudioClip playAudio;
protected AudioClip loopAudio;
protected AudioClip stopAudio;
// Declare Buttons
private JButton jplay = new JButton("PLAY");
private JButton jloop = new JButton("LOOP");
private JButton jstop = new JButton("STOP");
private boolean isStandalone = false;
public static void main(String [] args)
{
// Create a frame
MyFrameWithExitHandling frame = new MyFrameWithExitHandling(
"Lab14_1 Application");
// Crate an instance of the applet
Lab14_1 applet = new Lab14_1();
applet.isStandalone = true;
// Add the applet instance to the frame
frame.getContentPane().add(applet, BorderLayout.CENTER);
// Invoke init() and start()
applet.init();
applet.start();
// Display the frame
frame.pack();
frame.center();
frame.setVisible(true);
}
public void init()
{
if (!isStandalone)
{
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(jplay);
p.add(jloop);
p.add(jstop);
getContentPane().add(p);
// Create audio clips for playAudio, loopAudio
playAudio = getAudioClip(getCodeBase(),
"Chapter14/Airplane.wav");
loopAudio = getAudioClip(getCodeBase(),
"Chapter14/Chimp.wav");
// Register Listeners
jplay.addActionListener(this);
jloop.addActionListener(this);
jstop.addActionListener(this);
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jplay)
{
playAudio.play();
}
if (e.getSource() == jloop)
{
loopAudio.loop();
}
if (e.getSource() == jstop)
{
playAudio.stop();
loopAudio.stop();
}
}
}
23 years ago
I can run this as an applet but not as an application. Can someone help make this program do either or?
import java.applet.*;
import java.awt.BorderLayout;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import Chapter8.MyFrameWithExitHandling;
public class Lab14_1 extends JApplet implements ActionListener
{
// Delcare Audio Files
static AudioClip playAudio;
protected AudioClip loopAudio;
protected AudioClip stopAudio;
// Declare Buttons
private JButton jplay = new JButton("PLAY");
private JButton jloop = new JButton("LOOP");
private JButton jstop = new JButton("STOP");
private boolean isStandalone = false;
public static void main(String [] args)
{
// Create a frame
MyFrameWithExitHandling frame = new MyFrameWithExitHandling(
"Lab14_1 Application");
// Crate an instance of the applet
Lab14_1 applet = new Lab14_1();
applet.isStandalone = true;
// Add the applet instance to the frame
frame.getContentPane().add(applet, BorderLayout.CENTER);
// Invoke init() and start()
applet.init();
applet.start();
// Display the frame
frame.pack();
frame.center();
frame.setVisible(true);
}
public void init()
{
if (!isStandalone)
{
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(jplay);
p.add(jloop);
p.add(jstop);
getContentPane().add(p);
// Create audio clips for playAudio, loopAudio
playAudio = getAudioClip(getCodeBase(),
"Chapter14/Airplane.wav");
loopAudio = getAudioClip(getCodeBase(),
"Chapter14/Chimp.wav");
// Register Listeners
jplay.addActionListener(this);
jloop.addActionListener(this);
jstop.addActionListener(this);
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jplay)
{
playAudio.play();
}
if (e.getSource() == jloop)
{
loopAudio.loop();
}
if (e.getSource() == jstop)
{
playAudio.stop();
loopAudio.stop();
}
}
}
23 years ago