/* ********************************************************* * * * Multimedia in Java * Computer and Information Science * Procedural Java = before thinking OOP * 2012 Goal : update using Java OOP and MVC * * * Lab #8 : Halloween Date: Oct 31/2002 * *******************************************************/ import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.net.*; public class Halloween implements ActionListener, Runnable { //ARRAY CODE ImageIcon[] images=new ImageIcon[3]; AudioClip[] audioclip= new AudioClip[2]; int frame= 1; int button= 2; // Intro of buttons Button bwitch=new Button("WITCH"); Button bghost=new Button("GHOST"); volatile Thread thread; JFrame jframe = new JFrame("Application version"); Drawing draw = new Drawing(); public Halloween() { // these are the picture files being used as well as the audioclips images[0] = new ImageIcon("C:\\comp sci\\eclipse java prog\\New Halloween OOP\\src\\flyingwitch.jpg"); images[1] = new ImageIcon("C:\\comp sci\\eclipse java prog\\New Halloween OOP\\src\\ghost.jpg"); images[2] = new ImageIcon("C:\\comp sci\\eclipse java prog\\New Halloween OOP\\src\\jack-o-lantern.jpg"); try{ audioclip[0] =Applet.newAudioClip(new URL("C:\\comp sci\\eclipse java prog\\New Halloween OOP\\src\\mywitch.au")); audioclip[1] =Applet.newAudioClip(new URL("C:\\comp sci\\eclipse java prog\\New Halloween OOP\\src\\Lalala.au")); // audioclip[2] =getAudioClip(getCodeBase(),"PATCH.AU"); } catch (MalformedURLException murle){}; jframe.add(draw); JPanel top = new JPanel(); top.add(bwitch); bwitch.addActionListener(this); top.add(bghost); bghost.addActionListener(this); jframe.add(top, "North"); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setSize(300,300); jframe.setVisible(true); } public void start() { (thread = new Thread (this)).start(); } public void stop() { thread = null; } class Drawing extends JComponent { public void paint (Graphics g) { g.drawImage(images[frame].getImage(),50,50,300,300,this); audioclip[frame].play(); // image and sound play as user mouse clicks on button button= 2; // button = 2 is default pumkin } } public void actionPerformed(ActionEvent e) { if (e.getSource()==bwitch) { button= 0; } else if (e.getSource()==bghost) { button = 1; } } public void run() { int delay = 6000; try { while (thread==Thread.currentThread()) { // changes screen into the picture that was chosen and then repaints the original screen frame = button; draw.repaint(); Thread.sleep(delay); } } catch (Exception e) { } }//end of NewHalloween program public static void main(String [] args) { new Halloween(); } }// Happy Halloween!!Download Easter Egg Image and Sound files
Multimedia Threaded Easter Egg Demo
Interactive GUI Demo with File Handling
Interactive Theatre Reservation - parallel arrays
Abstract Windows Toolkit - Sound, Images and GUI
OOP Multimedia Design Challenge