while(running) { renderGame(); updateGame(); paintScreen(); sleepTime = 100; if(sleepTime > 0) { try { Thread.sleep(50); } catch(Exception exc) { } } }
package Fireworks; import java.awt.*; import java.util.*; import java.applet.*; import javax.swing.*; import java.io.*; import java.net.*; import javax.sound.midi.*; import javax.sound.sampled.*; import java.applet.AudioClip; import java.awt.Container; import java.awt.Graphics2D; import java.awt.Image; import java.lang.*; public class Fireworks extends javax.swing.JApplet //public class Fireworks extends javax.swing.JFrame { Container gameContainer; FireworksPanel fwPanel; InstructionsPanel fwGuide; FireworksDisplay fwDisplay; public Fireworks() { //initComponents(); makeUI(); setSize(Constants.WIDTH, Constants.HEIGHT); setVisible(true); } public void makeUI() { fwDisplay = new FireworksDisplay(); fwGuide = new InstructionsPanel(); fwDisplay.setGame(this); fwGuide.setGame(this); GameDisplay(); add(fwDisplay); add(fwGuide); } public void GameDisplay() { fwDisplay.setEnabled(true); fwDisplay.setVisible(true); fwGuide.setEnabled(false); fwGuide.setVisible(false); } public void StartGame() { fwPanel = new FireworksPanel(); fwPanel.setGame(this); fwPanel.setFocusable(true); fwPanel.setEnabled(true); fwPanel.setVisible(true); add(fwPanel); fwDisplay.setEnabled(false); fwDisplay.setVisible(false); fwPanel.startGame(); // init(); /*JFrame frame = new JFrame ("Explosion"); frame.add (new ExplosionComponent ()); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.setSize (400, 400); frame.setVisible (true);*/ } public void GuideDisplay() { fwGuide.setEnabled(true); fwGuide.setVisible(true); fwDisplay.setEnabled(false); fwDisplay.setVisible(false); } public void Back() { fwDisplay.setVisible(true); fwDisplay.setEnabled(true); fwGuide.setVisible(false); fwGuide.setEnabled(false); } /* public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { ex.printStackTrace(); } } */ /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(0, 300, Short.MAX_VALUE) ); } // </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables /*public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable(){ public void run() { new Fireworks().setVisible(true); } }); }*/ }
package Fireworks; import java.awt.*; public class FireworksDisplay extends javax.swing.JPanel { Fireworks Game; //int width, height; public FireworksDisplay() { initComponents(); setSize(Constants.WIDTH, Constants.HEIGHT); //width = Constants.WIDTH; //height = Constants.HEIGHT; repaint(); } public void setGame(Fireworks Game) { this.Game = Game; } public Fireworks getGame() { return Game; } public void paintComponents(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.setFont(new Font("Times New Roman", Font.BOLD, 50)); g2d.setColor(Color.BLUE); g2d.drawString("Fireworks Display", Constants.WIDTH/2, Constants.HEIGHT/2); g2d.setFont(new Font("Times New Roman", Font.BOLD, 15)); g2d.drawString("Fireworks Display Program.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 40); g2d.drawString("Final Project, CS8680, Dr. Xu, KSU MSACS", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 60); g2d.drawString("Nathan Williams", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 80); g2d.drawString("Fall 2007.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 100); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); setLayout(null); jButton1.setLabel("Start Game"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); add(jButton1); jButton1.setBounds(220, 170, 110, 23); jButton2.setText("Instructions"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); add(jButton2); jButton2.setBounds(220, 200, 110, 23); }// </editor-fold>//GEN-END:initComponents private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed Game.GuideDisplay(); }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed Game.StartGame(); }//GEN-LAST:event_jButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; // End of variables declaration//GEN-END:variables }
package Fireworks; public class FireworksMove implements Moveable { private int currX, currY; private int nextVx, nextVy; private int nextX, nextY; public FireworksMove() { } public void calcVelocity() { } public void setCurrX(int x) { this.currX = x; } public int getCurrX() { return this.currX; } public void setCurrY(int y) { this.currY = y; } public int getCurrY() { return this.currY; } public void setNextVx(int vx) { this.nextVx = vx; } public void setNextVy(int vy) { this.nextVy = vy; } public int getNextVx() { return this.nextVx; } public int getNextVy() { return this.nextVy; } public int getNextX() { return this.nextX; } public void setNextX(int nextX) { this.nextX = nextX; } public int getNextY() { return this.nextY; } public void setNextY(int y) { this.nextY = y; } public void setPosition(int x, int y) { this.setCurrX(x); this.setCurrY(y); } public void setVelocity(int vx, int vy) { this.setNextVx(vx); this.setNextVy(vy); } public void updatePosition() { this.setNextX(getCurrX() + getNextVx()); this.setNextY(getCurrY() + getNextVy()); } }
package Fireworks; import java.awt.*; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Graphics; import java.awt.Point; import java.util.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.lang.Thread; import java.lang.Math; import java.lang.*; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; public class FireworksSprite extends Sprite2D implements Runnable { FireworksMove fwm; PropertyChangeSupport propChange; boolean launched; private long LaunchTime; private long ExplodeTime; double seed; int[] vx, vy; public int PosX, PosY; int dx, dy, x, y; // AnimationSprite explosion; Thread thread; //private FireworksExplosionSprite bomb_Burst[]; private FireworksSprite explosion[]; private FireworksSprite oneExplosion; private BufferedImage burst[]; int gravity = 20; int time = 0; int RocketX[], RocketY[]; int burstCount = 90; int length = 150; Random random; public FireworksSprite() { super(); propChange = new PropertyChangeSupport(this); fwm = new FireworksMove(); LaunchTime = 0; ExplodeTime = 10; fwm.setVelocity(1,-5); launched = false; } public void setFireworksVelocity(int x, int y) { fwm.setVelocity(x, y); } public void run() { } public void paintSprite(Graphics2D g2d) { if(isVisible()) { Random r = new Random(); Color color = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); g2d.setColor(color); g2d.fillOval(this.getLocx(), this.getLocy(), 5, 5); // call explosion once firework reaches alt of 15. if(this.getLocy()<=50 && this.getLocy()<=15) { //public void initBurst(Graphics2D g) //{ /* burst = new BufferedImage[3]; try { burst[0] = ImageIO.read(getClass().getResource("images\\one.gif")); burst[1] = ImageIO.read(getClass().getResource("images\\two.gif")); burst[2] = ImageIO.read(getClass().getResource("images\\three.gif")); //burst[3] = ImageIO.read(getClass().getResource(".gif")); //burst[4] = ImageIO.read(getClass().getResource(".gif")); //burst[5] = ImageIO.read(getClass().getResource(".gif")); //burst[6] = ImageIO.read(getClass().getResource(".gif")); //burst[7] = ImageIO.read(getClass().getResource(".gif")); //burst[8] = ImageIO.read(getClass().getResource(".gif")); //burst[9] = ImageIO.read(getClass().getResource(".gif")); }catch (Exception ex){System.out.println("Invalid Image");} for(int i = 0; i < burst.length; i ++) { //for(int t = 0; t < 100; t ++) //{ g2d.drawImage((BufferedImage)burst[i], 150, 150, null); try { thread.sleep(100); } catch(InterruptedException x){} //} } */ //load the explosion /*explosion = new AnimationSprite(this, g2d); explosion.load("explosion96x96x16.png", 4, 4, 96, 96); explosion.setFrameDelay(2); explosion.setAlive(false);*/ //startExplosion //this.getLocx(), this.getLocy(), g); //drawExplosions } } } public void initExplosion() { } public void updateSprite() { if(isVisible()) { fwm.setVelocity(fwm.getNextVx(), fwm.getNextVy()); fwm.setPosition(this.getLocx(), this.getLocy()); fwm.updatePosition(); this.setLocx(fwm.getNextX()); this.setLocy(fwm.getNextY()); rocketDecay(); fireNewLocation(new Point(this.getLocx(), this.getLocy())); } } public void fireNewLocation(Point p) { Point oldLoc = new Point(0,0); Point newLoc = p; propChange.firePropertyChange("NewP",oldLoc,newLoc); } private void rocketDecay() { if(this.getLocy() <= 0 || this.getLocy() > 1000) { //firework no longer visible this.setActive(false); this.setVisible(false); } //initBurst(PosX, PosY); } public void addPropertyChangeListener(PropertyChangeListener listener) { propChange.addPropertyChangeListener(listener); } public long getLaunchTime() { return this.LaunchTime; } public boolean isLaunched() { return this.launched; } public void setLaunched(boolean bool) { this.launched = bool; } public void setLaunchTime(long LaunchTime) { this.LaunchTime = LaunchTime; } public long getExplodeTime() { return this.ExplodeTime; } public void setExplodeTime(long ExplodeTime) { this.ExplodeTime = ExplodeTime; } public void setVel(int x, int y) { fwm.setVelocity(x, y); } } /*a = r.nextInt(50); //(int)Math.random(); v = r.nextInt(50); //(int)Math.random(); System.out.println("a = " + a); System.out.println("v = " + v); valueA = v*Math.sin(a)*t; valueB = (.5)*gravity*(t*t); dx = v*Math.cos(a)*t; dy = valueA - valueB; //v*Math.sin(a)*t-.5gravity*t*t; System.out.println("dx = " + dx); System.out.println("dy = " + dy);*/ /* class FireworksExplosionSprite { public int powerLevel; public int burstCount; public int length_of_stream; public int gravity; public int time; public int[] vx, vy; public int x, y; public double seed; Color color; public boolean sleep = true; private int dx, dy; private Random random; public FireworksExplosionSprite(int xSprite, int ySprite, int g) { dx = xSprite; dy = ySprite; gravity = g; } public void initExplosion(int power, int burst, int length, Color burstColor, long seed) { powerLevel = power; burstCount = burst; length_of_stream = length; color = burstColor; random = new Random(seed); vx = new int[burstCount]; vy = new int[burstCount]; for(int i = 0; i < burstCount; i ++) { vx[i] = (int)(Math.random()*powerLevel)-powerLevel/2; vy[i] = (int)(Math.random()*powerLevel*7/8)-powerLevel/8; } } public void start() { time = 0; sleep = false; } */ /*public void setExplosionSpeed(int burstSpeed) { } public int getExplosionSpeed(int burstSpeed) { return burstSpeed; } public void setExplosionStyle(int burstSpeed) { } public int getExplosionStyle(int burstSpeed) { return burstSpeed; } public void setBurstEnergy(int burstSpeed) { } public int getBurstEnergy(int burstSpeed) { return burstSpeed; } public void setRocketNumber(int burstSpeed) { } public int getRocketNumber(int burstSpeed) { return burstSpeed; } public void setBurstCount(int burstSpeed) { } public int getBurstCount(int burstSpeed) { return burstSpeed; } public void setRocketTailLength(int burstSpeed) { } public int getRocketTailLength(int burstSpeed) { return burstSpeed; } public void setGravityStrength(int burstSpeed) { } public int getGravityStrength(int burstSpeed) { return burstSpeed; }*/ /* public void paint(Graphics g) { if(!sleep) { if(time < length_of_stream) { double s; for(int i = 0; i < burstCount; i ++) { s = (double)time/100; x = (int)(vx[i]*s); y = (int)(vy[i]*s-gravity*s*s); g.setColor(Color.YELLOW); //color); g.drawLine(dx + x, dy - y, dx + x, dy - y); if(time >= length_of_stream/2) { for(int k = 0; k < burstCount; k ++) { s = (double)((time-length_of_stream/2)*2+k)/100; x = (int)(vx[i]*s); y = (int)(vy[i]*s-gravity*s*s); g.setColor(Color.BLACK); g.drawLine(dx + x, dy - y, dx + x, dy - y); } } } time ++; } else { sleep = true; } } }*/ //} /* int i; int e = 200; int p = 100; int l = 100; long s = (long)(Math.random()*10000); boolean sleep; //Graphics g = getGraphics(); while(true) { try { animation.sleep(20); } catch(InterruptedException x){} sleep=true; for(i=0;i<MaxRocketNumber;i++) sleep=sleep&&bomb_Burst[i].sleep; if(sleep&&Math.random()*100<RocketStyleVariability) { e=200; p=100; l=100; s=(long)(Math.random()*10000); } // } for(i=0;i<MaxRocketNumber;i++) { if(bomb_Burst[i].sleep&&Math.random()*MaxRocketNumber*l<1) { bomb_Burst[i].initExplosion(e,p,l,Color.YELLOW,s); bomb_Burst[i].start(); } bomb_Burst[i].paint(g); } } */ /*int AnimationSpeed = 100; int RocketValue = 20; int RocketCount = 10; int RocketPower = 500; int RocketBurstCount = 50; int RocketBurstLength = 100; int time = 0; int power, burst, length; int dx, dy; int RocketX[], RocketY[]; int Gravity = 20; Random random; //mx=350; //my=200; power =(int)(Math.random()*RocketPower*3/4) + RocketPower/4+1; burst =(int)(Math.random()*RocketCount*3/4) + RocketCount/4+1; length =(int)(Math.random()*RocketBurstLength*3/4) + RocketBurstLength/4+1; int i; long seed=(long)(Math.random()*10000); boolean sleep; while(true) { try { animation.sleep(100/AnimationSpeed); } catch(InterruptedException err){} sleep=true; if(sleep&&Math.random()*100<RocketValue) { power = 200; burst = 100; length = 100; seed=(long)(Math.random()*10000); } random=new Random(seed); RocketX=new int[burst]; RocketY=new int[burst]; dx=150; dy=150; for(i=0;i<burst;i++) { RocketX[i]=(int)(Math.random()*power)-power/2; RocketY[i]=(int)(Math.random()*power*7/8)-power/8; } if(time<length) { double sl; Color color; for(i=0;i<burst;i++) { sl=(double)time/100; x=(int)(RocketX[i]*sl); y=(int)(RocketY[i]*sl-Gravity*sl*sl); g.setColor(Color.YELLOW); g.drawLine(dx+x,dy-y,dx+x,dy-y); if(time>=length/2) { int j; for(j=0;j<2;j++) { sl=(double)((time-length/2)*2+j)/100; x=(int)(RocketX[i]*sl); y=(int)(RocketY[i]*sl-Gravity*sl*sl); g.setColor(Color.black); g.drawLine(dx+x,dy-y,dx+x,dy-y); } } } time++; } }*/ //Explosion = new FireworksSprite[30]; /*for(int i = 0; i < Explosion; i++) { double a = Math.random() * 2.0f * 3.1415f; double r = Math.random() * 1.0f; double dx = Math.cos(a) * r; double dy = Math.sin(a) * r; //Explosion[i] = new Bullet(x0, y0, dx0 + dx, dy0 + dy, _g, _size, _xmax, _ymax, _trail, _life_len, _fg, _bg); }*/ /* AnimationSpeed = 1; RocketStyleVariability = 10; MaxRocketNumber = 1; MaxRocketExplosionEnergy = 500; MaxRocketPatchNumber = 90; MaxRocketPatchLength = 150; Gravity = 20; bomb_Burst = new FireworksExplosionSprite[MaxRocketNumber]; for(int i = 0; i < MaxRocketNumber; i ++) bomb_Burst[i] = new FireworksExplosionSprite(x, y, Gravity);*/ /* int AnimationSpeed = 100; int RocketValue = 20; int RocketCount = 10; int RocketPower = 500; int RocketBurstCount = 50; int RocketBurstLength = 100; int time = 0; int power, burst, length; int dx, dy; int RocketX[], RocketY[]; int Gravity = 20; Random random; mx=350; my=200; power =(int)(Math.random()*RocketPower*3/4) + RocketPower/4+1; burst =(int)(Math.random()*RocketCount*3/4) + RocketCount/4+1; length =(int)(Math.random()*RocketBurstLength*3/4) + RocketBurstLength/4+1; int i; long seed=(long)(Math.random()*10000); boolean sleep; while(true) { try { animation.sleep(100/AnimationSpeed); } catch(InterruptedException err){} sleep=true; if(sleep&&Math.random()*100<RocketValue) { power = 200; burst = 100; length = 100; seed=(long)(Math.random()*10000); } random=new Random(seed); RocketX=new int[burst]; RocketY=new int[burst]; dx=150; dy=150; for(i=0;i<burst;i++) { RocketX[i]=(int)(Math.random()*power)-power/2; RocketY[i]=(int)(Math.random()*power*7/8)-power/8; } if(time<length) { double sl; Color color; for(i=0;i<burst;i++) { sl=(double)time/100; x=(int)(RocketX[i]*sl); y=(int)(RocketY[i]*sl-Gravity*sl*sl); g.setColor(Color.RED); g.drawLine(dx+x,dy-y,dx+x,dy-y); if(time>=length/2) { int j; for(j=0;j<2;j++) { sl=(double)((time-length/2)*2+j)/100; x=(int)(RocketX[i]*sl); y=(int)(RocketY[i]*sl-Gravity*sl*sl); g.setColor(Color.black); g.drawLine(dx+x,dy-y,dx+x,dy-y); } } } time++; } //showBurst(x, y, g); }*/ /*public void initBurst(Graphics2D g) { int gravity, a, v, T, L, x, y; explosion = new FireworksSprite[100]; oneExplosion = new FireworksSprite(); double valueA, valueB, dx, dy; int t = 0; Random r = new Random(); for(t = 0; t < explosion.length; t ++) { gravity = 20; a = 15; //r.nextInt(5); v = 10; //r.nextInt(5); //System.out.println("a = " + a); //System.out.println("v = " + v); valueA = v*Math.sin(a)*t; valueB = (.5)*gravity*(t*t); dx = (int)v*Math.cos(a)*t; dy = (int)valueA - valueB; x = (int)dx; y = (int)dy; oneExplosion = new FireworksSprite(); oneExplosion.setSpriteH(15); oneExplosion.setSpriteW(10); oneExplosion.setLocx(x); oneExplosion.setLocy(y); oneExplosion.setActive(true); oneExplosion.setVisible(true); oneExplosion.setVel(0, v); //System.out.print("Iterating through Array" + t); /*explosion[t] = new FireworksSprite(); explosion[t].setSpriteH(15); explosion[t].setSpriteW(10); explosion[t].setLocx(x); explosion[t].setLocy(y); explosion[t].setActive(true); explosion[t].setVisible(true); explosion[t].setVel(0, v); for (int i = 0; i < explosion.length; i ++) { g.setColor(Color.YELLOW); g.fillOval(x, y, 25, 25); //g.drawLine(x, y, x+50, y+50); } } }*/ /* public void paintBurst(Graphics2D g) { for (int i = 0; i < 100; i ++) //explosion.length; i ++) { //explosion[i].paintSprite(g); } }*/ /* int i; int e = 200; int p = 100; int l = 100; long s = (long)(Math.random()*10000); boolean sleep; //Graphics g = getGraphics(); while(true) { try { animation.sleep(20); } catch(InterruptedException x){} sleep=true; for(i=0;i<MaxRocketNumber;i++) sleep=sleep&&bomb_Burst[i].sleep; if(sleep&&Math.random()*100<RocketStyleVariability) { e=200; p=100; l=100; s=(long)(Math.random()*10000); } }*/
package Fireworks; public interface Moveable { public abstract void setPosition(int x, int y); public abstract void setVelocity(int vx, int vy); public abstract void updatePosition(); }
package Fireworks; import java.awt.*; abstract class Sprite { protected boolean visible; protected boolean active; abstract void paintSprite(Graphics2D g); abstract void updateSprite(); public boolean isVisible() { return visible; } public void setVisible(boolean b) { visible = b; } public boolean isActive() { return active; } public void setActive(boolean b) { active = b; } public void suspend() { setVisible(false); setActive(false); } public void restore() { setVisible(true); setActive(true); } }
package Fireworks; import java.awt.*; abstract class Sprite2D extends Sprite { protected int locx; protected int locy; protected int spriteW; protected int spriteH; protected int xPoints[]; protected int yPoints[]; Color color; boolean fill; public void setLocx(int locx) { this.locx = locx; } public int getLocx() { return this.locx; } public void setLocy(int locy) { this.locy = locy; } public int getLocy() { return this.locy; } public void setSpriteH(int spriteH) { this.spriteH = spriteH; } public int getSpriteH() { return this.spriteH; } public void setSpriteW(int spriteW) { this.spriteW = spriteW; } public int getSpriteW() { return this.spriteW; } public void setFill(boolean b) { fill = b; } public boolean getFill() { return fill; } public boolean isFill() { return getFill(); } public void setColor(Color c) { color = c; } public Color getColor() { return color; } }
package Fireworks; public class Constants { static int SPEED = 3000; static int WIDTH = 500; static int HEIGHT = 500; static int FIREWORKS_COUNT = 500; static int SPINNER_COUNT = 500; static int ROCKET_COUNT = 500; // Constants.SONG I left blank since I don't know what type it is. }
Okay, I created this file for the Constants class. It might be better to have the real Constants (these are just random numbers):
Java Syntax (Toggle Plain Text)
package Fireworks; public class Constants { static int SPEED = 3000; static int WIDTH = 500; static int HEIGHT = 500; static int FIREWORKS_COUNT = 500; static int SPINNER_COUNT = 500; static int ROCKET_COUNT = 500; // Constants.SONG I left blank since I don't know what type it is. }
It won't compile without the SongSprite and InstructionsPanel classes though.
public class Constants { static public int WIDTH = 800; static public int HEIGHT = 800; static public int SPEED = 1000; static public int ROCKET_HEIGHT = 10; static public int ROCKET_WIDTH = 2; static public int FIREWORKS_COUNT = 10; static public int SPINNER_COUNT = 10; static public int ROCKET_COUNT = 10; static public String SONG = "WilliamTell.wav"; static public String BANG = "fireworks.wav"; public Constants() { } }
import java.io.IOException; import java.text.DecimalFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip ; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineListener; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException ; import javax.sound.midi.*; import javax.sound.sampled.*; import java.applet.AudioClip; import java.util.*; import java.applet.*; import javax.swing.*; import java.io.*; import java.net.*; public class SongSprite implements LineListener { private String name; private Clip SongClip; private String file; private DecimalFormat df; public SongSprite() { } public void setFilename(String Songfile) { this.file = file; } public String getFilename() { return file; } /*public void loadClip() { try { Sequence midiSong = MidiSystem.getSequence(getClass().getResource("WilliamTell.mid")); Sequencer midiSequence = MidiSystem.getSequencer(); midiSequence.setSequence(midiSong); midiSequence.open(); midiSequence.start(); } catch (MalformedURLException e) { } catch (IOException e) { } catch (InvalidMidiDataException e) { } catch (MidiUnavailableException e) {} } */ /* try { AudioClip FireworkSound = Applet.newAudioClip (getClass().getResource(filename)); FireworkSound.play (); } catch(Exception e) { System.out.println("Problem with " + filename); }*/ //URL url = getClass().getResource(explosion); //getAudioClip(url).play(); //getAudioClip(url).loop(); public void update(LineEvent SoundEvent) { SongClip.stop(); SongClip.setFramePosition(0); SongClip.start(); } public void close(){ if(SongClip != null){ SongClip.stop (); SongClip.close(); } } public void play() { if(SongClip != null) { SongClip.start(); } //else //System.out.Println("Invalid file selected."); } public void stop() { if(SongClip != null) { SongClip.stop(); } //else //System.out.Println("Invalid file selected."); } public void pause() { if(SongClip != null) SongClip.stop(); //else //System.out.Println ("Invalid file selected."); } public void resume() { if(SongClip != null) SongClip.start(); //else //System.out.Println("Invalid file selected."); } }
import java.awt.*; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.*; import java.awt.Container; import javax.swing.*; import javax.swing.JButton; import javax.imageio.ImageIO; public class InstructionsPanel extends javax.swing.JPanel { Fireworks Game; //Graphics g; public InstructionsPanel() { initComponents(); //paintComponent(g); } public void setGame(Fireworks Game) { this.Game = Game; } // Variables declaration - do not modify // End of variables declaration public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.setFont(new Font("TimesRoman", Font.BOLD,20)); g2d.setColor(Color.BLACK); g2d.setFont(new Font("Times New Roman", Font.BOLD, 15)); g2d.drawString("Fireworks Display", Constants.WIDTH/2 + 20, Constants.HEIGHT/2); g2d.drawString("Story Line: It is time for your town's annual Fireworks show.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 40); g2d.drawString("As a new Pyrotechnics expert in the region, you have been hired to conduct this year's festivities.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 60); g2d.drawString("Due to past shows, the audience will be a hard sale to please.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 80); g2d.drawString("Earn points for each display and make the crowd happy.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 100); g2d.drawString("Will you succeed where others have failed?", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 120); g2d.drawString("Instructions.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 160); g2d.drawString("Please click on a Firework type to launch a show to display.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 180); g2d.drawString("Each type of show earns points for the user.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 200); g2d.drawString("The objective is to reach a total of 100 points from Fireworks.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 220); g2d.drawString("Fireworks Rockets Show (Keyboard Letter C) -> 5 points.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 240); g2d.drawString("Fireworks Spinners show (Keyboard Letter V) -> 10 points.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 260); g2d.drawString("Finale show (all types) (Keyboard Letter B) -> 15 points.", Constants.WIDTH/2 + 20, Constants.HEIGHT/2 + 280); } // <editor-fold defaultstate="collapsed" desc=" Generated Code "> private void initComponents() { jButton1 = new javax.swing.JButton(); jButton1.setText("Back"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(jButton1) .addContainerGap(335, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(jButton1) .addContainerGap(266, Short.MAX_VALUE)) ); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Game.Back(); } // Variables declaration - do not modify private javax.swing.JButton jButton1; // End of variables declaration }
Had to comment out the "org.jdesktop.layout.GroupLayout" lines since my NetBeans installation couldn't find them. I uncommented the "Fireworks.java" main function and ran that (I assume that's the main file to run?). I see no calls to the AbsFireworksPanel "run" function, so it's not just the println command that's not being implemented. The entire "run" function is not called. So I'm not sure which "main" is supposed to be implemented, where "run" is supposed to be called from for AbsFireworksPanel, and like I said, at least my Java installation can't handle the "org.desktop.layout.GroupLayout" lines since it can't find that package.
I should have mentioned what IDE I'm using.....Sun Java Studio Enterprise 8.1 (it generates some of the stuff that your system didn't like).
As for the primary file, the fireworks.java is the correct one. I'll look through the run() statement again, but it should only be handling the outer instantiation of the program (start game, end game, blah blah).
I'll still have this window up if you have any questions......I'm *STILL* trying to figure this mess out.
System.out.println("TEST EXPLODE!!");
Well, your test line:
is in the run function of AbsFireworksPanel and you were saying it doesn't print, so if that function is never called from anywhere, it's no surprise that it doesn't print. If all you want it to do is handle the outer stuff and it has nothing to do with where the explosion is being painted, maybe you should have your run function with the Thread sleep in the Fireworks class and take it out of AbsFireworksPanel.Java Syntax (Toggle Plain Text)
System.out.println("TEST EXPLODE!!");
Well, your test line:
is in the run function of AbsFireworksPanel and you were saying it doesn't print, so if that function is never called from anywhere, it's no surprise that it doesn't print. If all you want it to do is handle the outer stuff and it has nothing to do with where the explosion is being painted, maybe you should have your run function with the Thread sleep in the Fireworks class and take it out of AbsFireworksPanel.Java Syntax (Toggle Plain Text)
System.out.println("TEST EXPLODE!!");
| DaniWeb Message | |
| Cancel Changes | |