About two weeks ago, I was given a simple project in Java II; code a program that displays an image, plays a sound, and has loop/play/stop buttons for the sound and zoom in/zoom out buttons for the image. I decided to go ahead in the book with this project to get into some actual web development; I wanted to be able to have a real applet that people would be able to see if they accessed it on a server; basically, instead of referencing local variables, I accessed information stored on a remote server (http://lucarioboards.com) I explained all of this to her in an email in addition to in person, but she didn't read the email or seem to understand what I was saying.
After showing her my code, she said it was impossible to reference a "website" (the links I had to the image and sound from Java), and that I would have to "code a program to access the internet". I politely asked her to run the program, which runs perfectly on my computer (Windows Vista, compiled with NetBeans, while she uses XP and TextPad), and it compiled with errors (as well as a pop-up from her firewall, which was likely the source of the errors). She asked me to substitute in the filenames for the links and send it back to her.
Unfortunately, I cannot get the program to run with local resources instead of web resources. At least not in the state it's in. The page of my book that teaches how to access local images is, of course, missing... another reason (in addition to thinking I'd impress the teacher) I skipped ahead in the book to find a harder and better way to do this.
Here's my code:
//Programmer's name:
//Program purpose: To zoom in/out of an image while playing a song, which you can play/stop/loop.
// import packages
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.applet.*;
//extend from applet
public class WhatTimeIsIt extends Applet{
//declare 3 panels
private JPanel buttonPanel, imageBorder, totalBorder;
//declare 5 buttons
private Button playButton, loopButton, stopButton, zoomButton, shrinkButton;
//desclare one image
private Image zidane;
//declare one audio clip
private AudioClip audioClip;
private double scaleValue;
//declare two integers
int x = 450;
int y = 600;
public void init(){
//declare the three panels
totalBorder = new JPanel();
buttonPanel = new JPanel();
imageBorder = new JPanel();
//add play, loop, stop, zoom in, and zoom out buttons to the buttonPanel
playButton = new Button(" Play ");
buttonPanel.add(playButton,BorderLayout.SOUTH);
loopButton = new Button(" Loop ");
buttonPanel.add(loopButton,BorderLayout.SOUTH);
stopButton = new Button(" Stop ");
buttonPanel.add(stopButton,BorderLayout.SOUTH);
zoomButton = new Button(" Zoom In ");
shrinkButton = new Button(" Zoom Out ");
buttonPanel.add(zoomButton,BorderLayout.SOUTH);
buttonPanel.add(shrinkButton,BorderLayout.SOUTH);
//get the audio clip from a remote server
audioClip = getAudioClip(getCodeBase(), "http://lucarioboards.com/JazzPiano.mid");
//play the audio clip
audioClip.play();
//get image from a remote server
zidane = getImage(getCodeBase(),"http://lucarioboards.com/LucarioAndAaron.jpg");
add(imageBorder,BorderLayout.NORTH);
add(totalBorder,BorderLayout.CENTER);
add(buttonPanel,BorderLayout.SOUTH);
zoomButton.addActionListener(
//add new actionlistener
new ActionListener(){
public void actionPerformed (ActionEvent e){
//when zoom button is clicked, double image size
x = x * 2;
y = y * 2;
//repaint
repaint();
//show status
showStatus("Zoom in button is clicked");
}});
shrinkButton.addActionListener(
new ActionListener(){
//when zoom out button is clicked, halve image size
public void actionPerformed (ActionEvent e){
x = x / 2;
y = y / 2;
//repaint
repaint();
//show status
showStatus("Zoom out button is clicked");
}});
loopButton.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent e){
//when loop button is clicked, loop the music
audioClip.loop();
//show status
showStatus("Loop button is clicked");
}});
//when play button is clicked, play the music
playButton.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent e){
audioClip.play();
//show status
showStatus("Play button is clicked");
}});
stopButton.addActionListener(
new ActionListener(){
public void actionPerformed (ActionEvent e){
//when stop button is clicked, stop the music
audioClip.stop();
//show status
showStatus("Stop button is clicked");
}
});
}
//paint method
public void paint(Graphics g) {
//draw image
g.drawImage(zidane, 0, 0, x, y, imageBorder);
}
}
and my HTML file:
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<!--
*** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER ***
If you need to modify this HTML launcher file (e.g., to add applet parameters),
copy it to where your applet class is found in the SRC folder. If you do this,
the IDE will use it when you run or debug the applet.
Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in
the Packaging page in the Project Properties dialog.
For more information see the online help.
-->
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="WhatTimeIsIt.class" width=350 height=200></APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>
This was due three days ago. I fear I'm just going to be given a failing grade in it, despite going beyond the requirements, because my teacher can't understand what I did.
Please help.
Did I do something wrong I'm not seeing here? Why's it run on my computer? Is it because she's essentially compiling it in a text editor, or is it her firewall?
BTW: When I upload the HTML file to my server along with the Applet, the music plays, but the file never finishes loading. Why is this?
Thanks
~Will