CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Feb 2011
    Posts
    19

    Abstract error that i don't understand.

    Hey,

    So im getting an error that says that my class is not abstract and can't overun the abstract method im trying to use ( Action Performed ) well if anyone can figure out the error or give some input on this the files are linked below:

    the error is:

    Didier$ javac *.java
    GameInterface.java:7: GameInterface is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    public class GameInterface extends JFrame implements ActionListener{
    ^
    1 error
    The file that has the error:

    GameInterface.java

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import javax.swing.JComponent.*;
    
    public class GameInterface extends JFrame implements ActionListener{
    
    	GridForGame gridForGame = new GridForGame();
    
    	public GameInterface(){
    		super("Bubble Breaker - Java Version. By Gary Tremarco");
    		buildGUI();
    		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    		pack();
    		setVisible(true);
    		setResizable(false);
    	}
    	
    	private void buildGUI(){
    		JPanel main = new JPanel(new BorderLayout());
    		add(main, BorderLayout.CENTER);
    		
    		JPanel menu = new JPanel();
    		menu.setLayout(new BoxLayout(menu, BoxLayout.Y_AXIS));
    		menu.setPreferredSize(new Dimension(150,300));
    		Dimension buttonSize = new Dimension(120,40);
    		
    		addButton("8 x 8 Grid", "small", buttonSize, menu);
    		addButton("12 x 12 Grid", "medium", buttonSize, menu);
    		addButton("16 x 16 Grid", "large", buttonSize, menu);
    		addButton("How To Play", "howToPlay", buttonSize, menu);
    		addButton("Options", "options", buttonSize, menu);
    		addButton("Quit", "quitGame", buttonSize, menu);
    		
    		menu.setBorder(new TitledBorder(new EtchedBorder(4, Color.blue, Color.black), "Menu"));
    		JPanel buttons = new JPanel(new GridLayout(1,1));
    		buttons.add(menu);
    		
    		main.add(buttons, BorderLayout.EAST);
    		main.add(gridForGame, BorderLayout.CENTER);
    		
    	}
    	
    	public void addButton(String label, String command, Dimension size, JPanel panel){
    		
    		JButton button = new JButton(label);
    		button.setPreferredSize(size);
    		button.setMaximumSize(size);
    		Dimension seperatorSize = new Dimension(0,5);
    		button.setAlignmentX(CENTER_ALIGNMENT);
    		button.addActionListener(this);
    		button.setActionCommand(command);
    		panel.add(Box.createRigidArea(seperatorSize));
    		panel.add(button);
    	}
    	
    	public void ActionPerformed(ActionEvent ae){
    		
    		String command = ae.getActionCommand();
    		if (command == "small"){
    			gridForGame.small();
    		}
    		
    		if (command == "medium"){
    			gridForGame.medium();
    		}
    		
    		if (command == "large"){
    			gridForGame.large();
    		}
    		
    		if(command.equals("howToPlay")){
    			// check source code for URL that goes here
    		}
    		
    		if(command.equals("options")){
    			// check source image for code that goes here
    		}
    		
    		if(command == "quitGame"){
    			int selectedValue = JOptionPane.showConfirmDialog(null, "If Your Quit The Game All Data Will Be Lost" +
    				"\n" + "Are You Sure You Want To Quit?", "Attention", JOptionPane.YES_NO_OPTION);
    			// Might be issues above due to splitting brackets onto lines
    			
    			if(selectedValue == JOptionPane.NO_OPTION)
    				return;
    			
    			else System.exit(0);
    			
    		}
    	}
    	
    	public static void main( String args[]){
    		GameInterface i = new GameInterface();
    		i.addWindowListener(new WindowAltering());
    	}
    	
    	static class WindowAltering extends WindowAdapter{
    		public void windowClosing(WindowEvent e ){
    			int selectedValue = JOptionPane.showConfirmDialog(null, "Closing This Window Will End the Game." +
    				"\n" + "Click Yes To Exit", "Exit Bubble Breaker Game?", JOptionPane.YES_NO_OPTION);
    			if(selectedValue == JOptionPane.NO_OPTION)
    				return;
    			
    			else System.exit(0);
    		}
    	}
    }
    and its accompanied file:

    http://www.didierd.co.uk/bubble/GridForGame.java

    or if you don't feel comfortable downloading the files, i can put the source anywhere else if you like?

    Thank you for any help!
    Last edited by DidierD; February 3rd, 2011 at 11:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured