home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Sample.bin
/
SoundPlayerClass.java
< prev
next >
Wrap
Text File
|
1998-11-05
|
6KB
|
206 lines
/*
A basic extension of the java.awt.Frame class
*/
import java.awt.*;
import symantec.itools.awt.ImageButton;
import symantec.itools.multimedia.SoundPlayer;
import symantec.itools.multimedia.ImageViewer;
public class SoundPlayerClass extends Frame
{
public SoundPlayerClass()
{
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setBackground(java.awt.Color.lightGray);
setSize(400,300);
setVisible(false);
try {
imageButton2.setImageURL(symantec.itools.net.RelativeURL.getURL("images/play.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
add(imageButton2);
imageButton2.setBounds(240,145,57,58);
try {
imageButton1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/stop.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
add(imageButton1);
imageButton1.setBounds(136,145,57,58);
try {
imageViewer1.setImageURL(symantec.itools.net.RelativeURL.getURL("images/right.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
add(imageViewer1);
imageViewer1.setBounds(42,7,136,131);
try {
java.net.URL[] tempURL = new java.net.URL[5];
tempURL[0] = symantec.itools.net.RelativeURL.getURL("sounds/T1.au");
tempURL[1] = symantec.itools.net.RelativeURL.getURL("sounds/T2.au");
tempURL[2] = symantec.itools.net.RelativeURL.getURL("sounds/T3.au");
tempURL[3] = symantec.itools.net.RelativeURL.getURL("sounds/T4.au");
tempURL[4] = symantec.itools.net.RelativeURL.getURL("sounds/T5.au");
soundPlayer1.setURLList(tempURL);
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
//$$ soundPlayer1.move(212,61);
try {
imageViewer2.setImageURL(symantec.itools.net.RelativeURL.getURL("images/right.gif"));
}
catch (java.net.MalformedURLException error) { }
catch(java.beans.PropertyVetoException e) { }
add(imageViewer2);
imageViewer2.setBounds(251,7,136,131);
setTitle("A Simple Frame");
//}}
//{{INIT_MENUS
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
imageButton2.addActionListener(lSymAction);
imageButton1.addActionListener(lSymAction);
//}}
}
public SoundPlayerClass(String title)
{
this();
setTitle(title);
}
/**
* Shows or hides the component depending on the boolean flag b.
* @param b if true, show the component; otherwise, hide the component.
* @see java.awt.Component#isVisible
*/
public void setVisible(boolean b)
{
if(b)
{
setLocation(50, 50);
}
super.setVisible(b);
}
static public void main(String args[])
{
(new SoundPlayerClass()).setVisible(true);
}
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension d = getSize();
super.addNotify();
if (fComponentsAdjusted)
return;
// Adjust components according to the insets
Insets insets = getInsets();
setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
Component components[] = getComponents();
for (int i = 0; i < components.length; i++)
{
Point p = components[i].getLocation();
p.translate(insets.left, insets.top);
components[i].setLocation(p);
}
fComponentsAdjusted = true;
}
// Used for addNotify check.
boolean fComponentsAdjusted = false;
//{{DECLARE_CONTROLS
symantec.itools.awt.ImageButton imageButton2 = new symantec.itools.awt.ImageButton();
symantec.itools.awt.ImageButton imageButton1 = new symantec.itools.awt.ImageButton();
symantec.itools.multimedia.ImageViewer imageViewer1 = new symantec.itools.multimedia.ImageViewer();
symantec.itools.multimedia.SoundPlayer soundPlayer1 = new symantec.itools.multimedia.SoundPlayer();
symantec.itools.multimedia.ImageViewer imageViewer2 = new symantec.itools.multimedia.ImageViewer();
//}}
//{{DECLARE_MENUS
//}}
class SymWindow extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == SoundPlayerClass.this)
SoundPlayerClass_WindowClosing(event);
}
}
void SoundPlayerClass_WindowClosing(java.awt.event.WindowEvent event)
{
setVisible(false); // hide the Frame
try {
// soundPlayer1 Stop the sound player
soundPlayer1.stop();
} catch (Exception e) {
}
}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == imageButton2)
imageButton2_actionPerformed(event);
else if (object == imageButton1)
imageButton1_actionPerformed(event);
}
}
void imageButton2_actionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
imageButton2_actionPerformed_Interaction1(event);
}
void imageButton2_actionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
// soundPlayer1 Start the sound player
soundPlayer1.play();
} catch (Exception e) {
}
}
void imageButton1_actionPerformed(java.awt.event.ActionEvent event)
{
// to do: code goes here.
imageButton1_actionPerformed_Interaction1(event);
}
void imageButton1_actionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
try {
// soundPlayer1 Stop the sound player
soundPlayer1.stop();
} catch (Exception e) {
}
}
}