Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] getCodeBase()

Started by BlackReign Apr 25, 2006 at 3:50 PM 1 replies 4k views
Original Post
BlackReign
BlackReign
Hi whn I try to compile the following code I get the message "cannot find symbol method getCodeBase". Any ideas?


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;






public class Pearson extends JApplet implements ActionListener {

	private JButton singleplayerButton, multiplayerButton, creditsButton,playsingleButton;
  
  private JPanel mainMenu = new JPanel();
  private JPanel singleplayerMenu = new JPanel();
  private JPanel multiplayerMenu = new JPanel();
  private JPanel creditsPanel = new JPanel();
  private JPanel singleplayerGame = new JPanel();
  
  private JLabel mainmenuTitle = new JLabel("Pearson v0.1");
  private JLabel singleplayermenuTitle = new JLabel("Single Player");
  private JLabel name = new JLabel("Name:");
  private JLabel difficulty = new JLabel("Difficulty:");
  
  private JTextField text = new JTextField(15);
  
  private CardDeck deck = new CardDeck();
  
  public void init() {         
        
    //main menu button set-up
    singleplayerButton = new JButton("Play");
    singleplayerButton.setActionCommand("play");

    multiplayerButton = new JButton("Multiplayer");
    multiplayerButton.setActionCommand("multiplayer");

    creditsButton = new JButton("Credits");
    creditsButton.setActionCommand("credits");
        
    //single player menu button set-up
    playsingleButton = new JButton("Play");
    playsingleButton.setActionCommand("playsingle");
    
      //Create the radio buttons.
    JRadioButton easySetting = new JRadioButton("Easy     ");
    easySetting.setActionCommand("easy");
    easySetting.setSelected(true);

    JRadioButton noviceSetting = new JRadioButton("Novice  ");
    noviceSetting.setActionCommand("novice");

    JRadioButton difficultSetting = new JRadioButton("Difficult");
    difficultSetting.setActionCommand("difficult");
    
    //Match the radio button background with the panel background
    easySetting.setOpaque(false);
    noviceSetting.setOpaque(false);
    difficultSetting.setOpaque(false);
    
    //Group the buttons
    
    ButtonGroup radiobuttonGroup = new ButtonGroup();
    radiobuttonGroup.add(easySetting);
    radiobuttonGroup.add(noviceSetting);
    radiobuttonGroup.add(difficultSetting);


       
    //Listeners for buttons in main menu panel
    singleplayerButton.addActionListener(this);
    multiplayerButton.addActionListener(this);
    creditsButton.addActionListener(this);
        
    //Listeners for buttons in single player menu panel
        
    playsingleButton.addActionListener(this);
    easySetting.addActionListener(this);
    noviceSetting.addActionListener(this);
    difficultSetting.addActionListener(this);

        
    //mainMenu panel set-up        
    mainMenu.setLayout(new BoxLayout( mainMenu, BoxLayout.Y_AXIS ) );
    
    mainmenuTitle.setAlignmentX(Component.CENTER_ALIGNMENT);
    singleplayerButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    multiplayerButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    creditsButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    
    mainMenu.add(Box.createVerticalStrut(30));
    mainMenu.add(mainmenuTitle);
    mainMenu.add(Box.createVerticalStrut(110));    
    mainMenu.add(singleplayerButton);
    mainMenu.add(Box.createVerticalStrut(30));
    mainMenu.add(multiplayerButton);
    mainMenu.add(Box.createVerticalStrut(30));
    mainMenu.add(creditsButton);
    
    mainMenu.setBackground(new Color(255,30,60));
    
    //singleplayerMenu set-up
    
    singleplayerMenu.setLayout(new BoxLayout(singleplayerMenu, BoxLayout.Y_AXIS ) );
    
    singleplayermenuTitle.setAlignmentX(Component.CENTER_ALIGNMENT);
    difficulty.setAlignmentX(Component.CENTER_ALIGNMENT);
    easySetting.setAlignmentX(Component.CENTER_ALIGNMENT);
    noviceSetting.setAlignmentX(Component.CENTER_ALIGNMENT);
    difficultSetting.setAlignmentX(Component.CENTER_ALIGNMENT);
    name.setAlignmentX(Component.CENTER_ALIGNMENT);
    playsingleButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    
    text.setMaximumSize(new Dimension(150, 25));

    
    singleplayerMenu.add(Box.createVerticalStrut(30));
    singleplayerMenu.add(singleplayermenuTitle);
    singleplayerMenu.add(Box.createVerticalStrut(75));
    singleplayerMenu.add(difficulty);
    singleplayerMenu.add(Box.createVerticalStrut(10));
    singleplayerMenu.add(easySetting);
    singleplayerMenu.add(noviceSetting);
    singleplayerMenu.add(difficultSetting);
    singleplayerMenu.add(Box.createVerticalStrut(30));
    singleplayerMenu.add(name);
    singleplayerMenu.add(text);
    singleplayerMenu.add(Box.createVerticalStrut(30));
    singleplayerMenu.add(playsingleButton);
   
    
    
    singleplayerMenu.setBackground(new Color(255,30,60));
        
    setContentPane(mainMenu);
  }

  public void actionPerformed(ActionEvent evt) {
    
    if (evt.getActionCommand().equals( "play" )) {
      setContentPane(singleplayerMenu);
     	validate();
    }
    else if (evt.getActionCommand().equals( "multiplayer" ) ) {
      setContentPane(multiplayerMenu);
     	validate();
      
    }
    else if (evt.getActionCommand().equals( "credits" ) ) {
      setContentPane(creditsPanel);
     	validate();
      
    }
    
    if (evt.getActionCommand().equals("playsingle")) {
      setContentPane(singleplayerGame);
      startsingleplayerGame();
     	validate();
    }
    
  }
  
  private void startsingleplayerGame() { 
  
    loadUI(1);
    
    deck.loadImages();
    
    deck.deal();
    
  
  }
  
  private void startmultiplayerGame() { 
  
    loadUI(2);
    
    deck.loadImages();
    
    deck.deal();
    
  
  }
  
  private void loadUI(int gameType) {
  
    if (gameType==1){
    	
    }
 
  }
  
}

class Player {
	
	

}

class CardDeck {
	
	 public void loadImages() {
	 	
	 	 Image[] hearts = new Image[13];
    
     for (int i = 0; i < 12; i++) {
            
       hearts = getImage(getCodeBase(), (i+2) + "h.gif");
		   
		 }
		   
		   Image[] images = new Image[9]; //array of 9 images


			 ImageIcon icon = new ImageIcon("cards/2h.gif"); // create icon
			 
			 images[0] = icon.getImage(); // get the Image from the icon

		   
		 }  
		   
		    
           
        
   


	
		public void deal(){
		
  }
	
	
}






Thanks in advance
Son of Cain
Son of Cain
Because you're inside the scope of class CardDeck, and hence, has no access to the method in the enclosing class...?

Son Of Cain
a.k.a javabeats at yahoo.ca
BlackReign
BlackReign
How would I be able to access the method?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.