Abstract error that i don't understand.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Abstract error that i don't understand.

  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 10:29 AM.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Abstract error that i don't understand.

    Please post your code and the error. See my sig for instructions.

    The best thing about a boolean is even if you are wrong, you are only off by a bit...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Feb 2011
    Posts
    19

    Re: Abstract error that i don't understand.

    is that better? ^ edited the original post...

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Abstract error that i don't understand.

    The point of the CODE tags is to keep the formatting so the code is readable...

    However, the error message tells you exactly what the problem is - your GameInterface class implements the ActionListener interface, but doesn't provide an implementation of the actionPerformed(..) method. Only an abstract class can implement an interface without providing implementations of its methods.

    Hint: GameInterface implements ActionPerformed(..), instead of actionPerformed(..). Java is case-sensitive.

    It’s OK to figure out murder mysteries, but you shouldn’t need to figure out code. You should be able to read it...
    Steve McConnell
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Feb 2011
    Posts
    19

    Re: Abstract error that i don't understand.

    Oh thank you dude! I've been staring at this code for a good hour, thanks for your set of eyes !

  6. #6
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Abstract error that i don't understand.

    Quote Originally Posted by DidierD View Post
    Oh thank you dude! I've been staring at this code for a good hour, thanks for your set of eyes !
    You're welcome Didier - one reason for the Java naming conventions is that it makes errors like that easy to spot - because you know a method name should always start with a lower-case letter, and Java error messages usually tell you what is wrong - once you understand what they're saying.

    Looking at code you wrote more than two weeks ago is like looking at code you are seeing for the first time...
    Dan Hurvitz
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  7. #7
    Join Date
    Feb 2008
    Posts
    966

    Re: Abstract error that i don't understand.

    Code:
    if (command == "large"){
           gridForGame.large();
    }		
     if(command.equals("howToPlay")){
           // check source code for URL that goes here
     }
    You might also want to go back and fix your conditional statements. You are using "==" to compare strings in some of them and ".equals()" method (the correct way) in others. Consistency.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center