Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[ Help ]

Newbie Spellweaver
Joined
Jul 15, 2010
Messages
63
Reaction score
2
i need help calling images from my constructor class and i also cannot get sound to play in the applet


Main Applet
Code:
package finalproject;


import java.applet.*;
import java.awt.*; 
import java.util.*;
import java.awt.event.*;
import java.io.*;
import sun.audio.*;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;


public class Guitarhero extends Applet implements KeyListener , Runnable{
 
    private int letter; 
    private notes[] keys;
    private notes pic;
    AudioClip song1;
    
   
       
       
        
   public void init(){
   
   
   song1 = getAudioClip(getCodeBase(), "scan.wav");
   song1.loop();
   addKeyListener(this); 
   
   
   // Key Arrays
   
   keys = new notes[9];
   
   for (int i=0;i<keys.length;i++){
       
       
       
      
       
       
       keys[i] = new notes(0,0); 
       
       
   }
   
   
   
   
   
   }     
   
   public void paint(Graphics g){

       
         for (int i=0;i<keys.length;i++){
            keys[i].paint(g);
            }
       
 g.drawOval(50,450,200,200); 
 g.drawOval(300,450,200,200); 
 g.drawOval(550,450,200,200);  
 
 for(int i=0;i<keys.length;i++){
 
  
 
 
 
 
 
 }
       
   }
   

   public void run() {
       
       
       
       
       
       
   }
        

    

  public void keyPressed(KeyEvent e) {

			if (e.getKeyCode() == KeyEvent.VK_A) {
                            song1.play();
                
			}

			else if (e.getKeyCode() == KeyEvent.VK_S) {

 
			}
			else if (e.getKeyCode() == KeyEvent.VK_D) {
                           
                            
                        }
                            
			else if (e.getKeyCode() == KeyEvent.VK_F) {



			}
			else if (e.getKeyCode() == KeyEvent.VK_G) {



			}
                        else if (e.getKeyCode() == KeyEvent.VK_G) {



			}
                        else if (e.getKeyCode() == KeyEvent.VK_H) {



			}
                        else if (e.getKeyCode() == KeyEvent.VK_I) {



			}
                        else if (e.getKeyCode() == KeyEvent.VK_J) {



			}
                        else if (e.getKeyCode() == KeyEvent.VK_K) {



			}
                        else if (e.getKeyCode() == KeyEvent.VK_L) {



			}


		}
		public void keyReleased(KeyEvent e) {



		}
		public void keyTyped(KeyEvent e) {


		}

    
    }



Constructor Class

Code:
package finalproject;

import java.awt.*;
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;




public class notes {
    
    
    private int x;
    private int y;
    private String notepress;
    private Image A;
    private Image S;
    private Image D;
    private Image F;
    private Image G;
    private Image H;
    private Image J;
    private Image K;
    private Image L;
    
    
    public void init(){
    try{
    A = ImageIO.read(new File("A.png"));
    S = ImageIO.read(new File("S.png"));
    D = ImageIO.read(new File("D.png"));
    F = ImageIO.read(new File("F.png"));
    G = ImageIO.read(new File("G.png"));
    H = ImageIO.read(new File("H.png"));
    J = ImageIO.read(new File("J.png"));
    K = ImageIO.read(new File("K.png"));
    L = ImageIO.read(new File("L.png"));
    
    }
    catch(Exception e){
        System.out.println("There was a problem loading the image");
    }
    
    
    }
    
    
    public void paint(Graphics g){
    x = 100;
    y = 100;
    if (notepress.equals ("A")){
    
    g.drawImage(A, x, y, null);
    
    }
    else if (notepress.equals ("S")){
    
    g.drawImage(S, x, y, null);
    }
    else if (notepress.equals ("D")){
    
    g.drawImage(D, x, y, null);
    }
    
    else if (notepress.equals ("F")){
    
    g.drawImage(F, x, y, null);
    }
    else if (notepress.equals ("G")){
    
    g.drawImage(G, x, y, null);
    }
    else if (notepress.equals ("H")){
    
    g.drawImage(H, x, y, null);
    }
    else if (notepress.equals ("J")){
    
    g.drawImage(J, x, y, null);
    }
    else if (notepress.equals ("K")){
    
    g.drawImage(K, x, y, null);
    }
    else if (notepress.equals ("L")){
    
    g.drawImage(L, x, y, null);
    }
    
    
    
    
    
    }
    
    
    
    
    
    public notes (int notex , int notey){
        
        x = notex;
        y = notey;
        double d = Math.random(); 
        
        if (d <= .10){
        
        notepress = "A"; 
        
        }
        else if (d <= .20){
    
        notepress = "S";
        
        }
        else if (d <= .30){
        
        notepress = "D";
        
        }
        else if(d <= .40){
            
        notepress = "F";
                
        }
        else if(d <= .50){
            
        notepress = "G";
                
        }
        else if(d <= .60){
            
        notepress = "H";
                
        }
        else if(d <= .70){
            
        notepress = "I";
                
        }
         else if(d <= .80){
            
        notepress = "J";
                
        }
         else if(d <= .90){
            
        notepress = "K";
                
        }
        else{
            
        notepress = "L";
                
        }
        
        
        
        
    }
    
    
    
    
}
 
Joined
Aug 10, 2011
Messages
7,401
Reaction score
3,299
Do you call:

Notes note = new Notes(x, y);
note.init();

Notice that classes should be defined with an Capital.

I don't quite understand what you are trying to achieve. Mostly because you don't follow any of the conventions. This could be due to inexperience or just being lazy. I hope the first tbh :p:

If you could show any exceptions / errors that would be appreciated.
 
Back
Top