Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Having a problem finding the error in my ActionListener method.

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having a problem finding the error in my ActionListener method.

    The error for the code on my program is : error: Lesson9_Menus is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener

    Here's the code, thanks for the help in advance!

    import java.*;
    import java.util.Random;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
     public class Lesson9_Menus extends JFrame implements ActionListener{
     
    	private Container win;
     
    	JFrame f;
    	Container subWin;
     
    	JLabel inputLabel, outputLabel;
    	JTextField inputField, outputField;
    	JButton calcButton, bd_calcButton, bh_calcButton, db_calcButton, dh_calcButton, hb_calcButton, hd_calcButton;
     
    	private String binIn, hexIn;
    	private int decimal, number;
     
    	JMenuBar menubar;
    	JMenu binaryToMenu, decimalToMenu, hexToMenu;
    	JMenuItem binToDecItem, binToHexItem, decToBinItem, decToHexItem, hexToDecItem, hexToBinItem;
     
    	public Lesson9_Menus(){
    		super("Conversion from Decimal to Binary / Hexadecimal");
    		win = getContentPane();
    		win.setLayout(null);
     
    		menubar= new JMenuBar();
     
     
    		binaryToMenu = new JMenu("Binary To");
    		decimalToMenu = new JMenu("Decimal To");
    		hexToMenu = new JMenu("Hex To");
     
    		binaryToMenu.setMnemonic('B');
    		decimalToMenu.setMnemonic('B');
    		hexToMenu.setMnemonic('B');
     
    		binToDecItem = new JMenuItem("Binary to Decimal");
    		binToHexItem = new JMenuItem("Binary to Hex");
    		decToBinItem = new JMenuItem("Decimal to Binary");
    		decToHexItem = new JMenuItem("Decimal to Hex");
    		hexToDecItem = new JMenuItem("Hex to Decimal");
    		hexToBinItem = new JMenuItem("Hex to Binary");
     
    		binToDecItem.addActionListener(this);
    		binToHexItem.addActionListener(this);
    		decToBinItem.addActionListener(this);
    		decToHexItem.addActionListener(this);
    		hexToBinItem.addActionListener(this);
    		hexToDecItem.addActionListener(this);
     
    		binaryToMenu.add(binToDecItem);
    		binaryToMenu.add(binToHexItem);
     
    		decimalToMenu.add(decToBinItem);
    		decimalToMenu.add(decToHexItem);
     
    		hexToMenu.add(hexToBinItem);
    		hexToMenu.add(hexToDecItem);
     
    		menubar.add(binaryToMenu);
    		menubar.add(decimalToMenu);
    		menubar.add(hexToMenu);
     
    		setJMenuBar(menubar);
     
    		number = 0;
     
    		setSize(600,300);
    		setVisible(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	}
    		public static void main(String[] arg){
    			javax.swing.SwingUtilities.invokeLater(new Runnable(){
    				public void run(){
    					new Lesson9_Menus();
    				}
    			});
    		}
     
    	public void actionPerfomed(ActionEvent event){
    		if(event.getSource() ==  binToDecItem)
    			react_binToDecItem();
     
    		else if(event.getSource() ==  binToHexItem)
    			react_binToHexItem();
     
    		else if(event.getSource() ==  decToBinItem)
    			react_decToBinItem();
     
    		else if(event.getSource() ==  decToHexItem)
    			react_decToHexItem();
     
    		else if(event.getSource() ==  hexToBinItem)
    			react_hexToBinItem();
     
    		else if(event.getSource() ==  hexToDecItem)
    			react_hexToDecItem();
     
    	}
    		public void react_binToDecItem(){
    		JFrame f = new JFrame("Binary to decimal"); 
    		subWin = f.getContentPane();
    		subWin.setLayout(null);
    		subWin.setPreferredSize(new Dimension(400,200));
     
    		inputLabel = new JLabel("Enter binary number");
    		inputLabel.setSize(new Dimension(175,20));
    		inputLabel.setLocation(10,50);
    		subWin.add(inputLabel);	
     
    		inputField = new JTextField("");
    		inputField.setSize(175,20);
    		inputField.setLocation(200,50);
    		subWin.add(inputField);
     
    		outputLabel = new JLabel("Decimal Number");
    		outputLabel.setSize(new Dimension(175,20));
    		outputLabel.setLocation(10,150);
    		subWin.add(outputLabel);
     
    		outputField = new JTextField("");
    		outputField.setSize(new Dimension(175,20));
    		outputField.setLocation(200,150);
    		subWin.add(outputField);
     
    		bd_calcButton = new JButton("Calculate");
    		bd_calcButton.setSize(150,30);
    		bd_calcButton.setLocation(100,80);
    		subWin.add(bd_calcButton);
    		bd_calcButton.addActionListener(new ButtonHandler());
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.pack();
    		f.setVisible(true);
    		}
     
    		public void react_binToHexItem(){
    		JFrame f = new JFrame("Binary to hexadecimal"); 
    		subWin = f.getContentPane();
    		subWin.setLayout(null);
    		subWin.setPreferredSize(new Dimension(400,200));
     
    		inputLabel = new JLabel("Enter binary number");
    		inputLabel.setSize(new Dimension(175,20));
    		inputLabel.setLocation(10,50);
    		subWin.add(inputLabel);	
     
    		inputField = new JTextField("");
    		inputField.setSize(175,20);
    		inputField.setLocation(200,50);
    		subWin.add(inputField);
     
    		outputLabel = new JLabel("Hexadecimal Number");
    		outputLabel.setSize(new Dimension(175,20));
    		outputLabel.setLocation(10,150);
    		subWin.add(outputLabel);
     
    		outputField = new JTextField("");
    		outputField.setSize(new Dimension(175,20));
    		outputField.setLocation(200,150);
    		subWin.add(outputField);
     
    		bh_calcButton = new JButton("Calculate");
    		bh_calcButton.setSize(150,30);
    		bh_calcButton.setLocation(100,80);
    		subWin.add(bh_calcButton);
    		bh_calcButton.addActionListener(new ButtonHandler());
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.pack();
    		f.setVisible(true);
    		}
    		public void react_hexToDecItem(){
    		JFrame f = new JFrame("Hex to Decimal"); 
    		subWin = f.getContentPane();
    		subWin.setLayout(null);
    		subWin.setPreferredSize(new Dimension(400,200));
     
    		inputLabel = new JLabel("Enter hexadecimal number");
    		inputLabel.setSize(new Dimension(175,20));
    		inputLabel.setLocation(10,50);
    		subWin.add(inputLabel);	
     
    		inputField = new JTextField("");
    		inputField.setSize(175,20);
    		inputField.setLocation(200,50);
    		subWin.add(inputField);
     
    		outputLabel = new JLabel("Decimal Number");
    		outputLabel.setSize(new Dimension(175,20));
    		outputLabel.setLocation(10,150);
    		subWin.add(outputLabel);
     
    		outputField = new JTextField("");
    		outputField.setSize(new Dimension(175,20));
    		outputField.setLocation(200,150);
    		subWin.add(outputField);
     
    		hd_calcButton = new JButton("Calculate");
    		hd_calcButton.setSize(150,30);
    		hd_calcButton.setLocation(100,80);
    		subWin.add(hd_calcButton);
    		hd_calcButton.addActionListener(new ButtonHandler());
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.pack();
    		f.setVisible(true);
     
    		}
    		public void react_hexToBinItem(){
    		JFrame f = new JFrame("Hex to Binary"); 
    		subWin = f.getContentPane();
    		subWin.setLayout(null);
    		subWin.setPreferredSize(new Dimension(400,200));
     
    		inputLabel = new JLabel("Enter hexadecimal number");
    		inputLabel.setSize(new Dimension(175,20));
    		inputLabel.setLocation(10,50);
    		subWin.add(inputLabel);	
     
    		inputField = new JTextField("");
    		inputField.setSize(175,20);
    		inputField.setLocation(200,50);
    		subWin.add(inputField);
     
    		outputLabel = new JLabel("Binary Number");
    		outputLabel.setSize(new Dimension(175,20));
    		outputLabel.setLocation(10,150);
    		subWin.add(outputLabel);
     
    		outputField = new JTextField("");
    		outputField.setSize(new Dimension(175,20));
    		outputField.setLocation(200,150);
    		subWin.add(outputField);
     
    		hb_calcButton = new JButton("Calculate");
    		hb_calcButton.setSize(150,30);
    		hb_calcButton.setLocation(100,80);
    		subWin.add(hb_calcButton);
    		hb_calcButton.addActionListener(new ButtonHandler());
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.pack();
    		f.setVisible(true);
     
    		}
    		public void react_decToBinItem(){
    		JFrame f = new JFrame("Decimal to Binary"); 
    		subWin = f.getContentPane();
    		subWin.setLayout(null);
    		subWin.setPreferredSize(new Dimension(400,200));
     
    		inputLabel = new JLabel("Enter decimal number");
    		inputLabel.setSize(new Dimension(175,20));
    		inputLabel.setLocation(10,50);
    		subWin.add(inputLabel);	
     
    		inputField = new JTextField("");
    		inputField.setSize(175,20);
    		inputField.setLocation(200,50);
    		subWin.add(inputField);
     
    		outputLabel = new JLabel("Binary Number");
    		outputLabel.setSize(new Dimension(175,20));
    		outputLabel.setLocation(10,150);
    		subWin.add(outputLabel);
     
    		outputField = new JTextField("");
    		outputField.setSize(new Dimension(175,20));
    		outputField.setLocation(200,150);
    		subWin.add(outputField);
     
    		db_calcButton = new JButton("Calculate");
    		db_calcButton.setSize(150,30);
    		db_calcButton.setLocation(100,80);
    		subWin.add(db_calcButton);
    		db_calcButton.addActionListener(new ButtonHandler());
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.pack();
    		f.setVisible(true);
     
    		}
    		public void react_decToHexItem(){
    		JFrame f = new JFrame("Decimal to Hexadecimal"); 
    		subWin = f.getContentPane();
    		subWin.setLayout(null);
    		subWin.setPreferredSize(new Dimension(400,200));
     
    		inputLabel = new JLabel("Enter decimal number");
    		inputLabel.setSize(new Dimension(175,20));
    		inputLabel.setLocation(10,50);
    		subWin.add(inputLabel);	
     
    		inputField = new JTextField("");
    		inputField.setSize(175,20);
    		inputField.setLocation(200,50);
    		subWin.add(inputField);
     
    		outputLabel = new JLabel("Hexadecimal Number");
    		outputLabel.setSize(new Dimension(175,20));
    		outputLabel.setLocation(10,150);
    		subWin.add(outputLabel);
     
    		outputField = new JTextField("");
    		outputField.setSize(new Dimension(175,20));
    		outputField.setLocation(200,150);
    		subWin.add(outputField);
     
    		dh_calcButton = new JButton("Calculate");
    		dh_calcButton.setSize(150,30);
    		dh_calcButton.setLocation(100,80);
    		subWin.add(dh_calcButton);
    		dh_calcButton.addActionListener(new ButtonHandler());
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.pack();
    		f.setVisible(true);	
     
    		}
     
           private class ButtonHandler implements ActionListener{
    			public void actionPerformed(ActionEvent e){
    				if(e.getSource() == bd_calcButton){
    					String binIn = inputField.getText();
    					decimal = 0;
    					int base = 1;
    					for(int i = binIn.length() -1; i >= 0; i--){
    						char letter = binIn.charAt(i);
    						if(letter == '1'){
    							decimal += base;
    							base*= 2;
    						}
     
    					}
    					outputField.setText("" + decimal);
     
    				}
    				if(e.getSource() == bh_calcButton){
    					String binIn = inputField.getText();
    					decimal = 0;
    					int base = 1;
    					for(int i = binIn.length() - 1; i>= 0; i--){
    						char letter = binIn.charAt(i);
    						if(letter == '1'){
    							decimal += base;
    							base*=2;
    						}
    					}
    						int rem = 0;
    						String result = "";
    						for(int hexbase = 4096; hexbase >0; hexbase/=16){
    							int hexval = decimal/hexbase;
    							rem = decimal/hexbase;
    							if(hexval >=10){
     
    							switch(hexval){
    								case 10 : result += ('A'); break;
    								case 11 : result += ('B'); break;
    								case 12 : result += ('C'); break;
    								case 13 : result += ('D'); break;
    								case 14 : result += ('E'); break;
    								case 15 : result += ('F'); break;
    							}
     
    							}
    							else
    								result += hexval;
    							if(hexval >= 0)
    								decimal = rem;
     
     
    						}
    						outputField.setText(result);
    					}
    					if(e.getSource() == hd_calcButton){
    						hexIn = inputField.getText().toUpperCase();
    						decimal = 0;
    						int base = 1;
     
    						for(int i = hexIn.length() - 1; i >= 0; i--){
    							int pos = 0;
    							char letter = hexIn.charAt(i);
    							if(Character.isDigit(letter))
    								pos = letter - 48;
    							else
    								pos = letter - 55;
    							decimal += pos * base;
    							base*= 16;
    						}
    						outputField.setText("" + decimal);
    					}
    					if(e.getSource() == hb_calcButton){
    						hexIn = inputField.getText().toUpperCase();
    						int bin1;
    						decimal = 0;
    						int base = 1;
     
    						for(int i = hexIn.length() - 1; i >= 0; i--){
    							int pos = 0;
    							char letter = hexIn.charAt(i);
    							if(Character.isDigit(letter))
    								pos = letter - 48;
    							else
    								pos = letter - 55;
    							decimal += pos * base;
    							base *= 16;
     
    							}
    							int number = decimal;
    							String result = "";
     
    							for(int twobase = 128; twobase >= 0; twobase /= 2){
    								bin1 = number /twobase;
    								result += ("" + bin1);
    								if(number >= twobase)
    									number -= twobase;
    							}
     
    							outputField.setText(result);
    						}
    						if(e.getSource() == db_calcButton){
    							int number = Integer.parseInt(inputField.getText());
    							int bin1;
    							String result = "";
    							for(int twobase = 128; twobase > 0; twobase/=2){
    								bin1 = number /twobase;
    								result += ("" + bin1);
     
    								if(number >= twobase)
    									number -= twobase;
     
    							}
    							outputField.setText(result);
    						}
    						if(e.getSource() == dh_calcButton){
    							int number = Integer.parseInt(inputField.getText());
    							int rem = 0;
    							 String result = "";
    							 for(int hexbase = 4096; hexbase > 0; hexbase /= 16){
    							 	int hexval = number / hexbase;
    							 	rem = number % hexbase;
     
    							 	if(hexval >= 10){
    							 		switch(hexval){
     
    							 		case 10 : result += ('A'); break;
    									case 11 : result += ('B'); break;
    									case 12 : result += ('C'); break;
    									case 13 : result += ('D'); break;
    									case 14 : result += ('E'); break;
    									case 15 : result += ('F'); break;	
     
    									}
    							 	}
    							 	else
    							 		result += hexval;
    							 	if(hexval >= 0)
    							 		number = rem;
    							 }
    							 outputField.setText(result);
    						}
    					}
     
     
     
     
    			}		
     
     
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Having a problem finding the error in my ActionListener method.

    Lesson9_Menus is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
    When a class implements an interface it is required to declare all the abstract methods declared in the interface.
    The compiler can not find a definition for the method: actionPerformed(ActionEvent) in the class that implements ActionListener.

    Did you forget to code that method or should the class NOT implement ActionListener?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How do I invoke a method to an ActionListener
    By susan28 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 27th, 2019, 09:09 PM
  2. Need help with ActionListener Error
    By Edmacelroy in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 2nd, 2013, 02:48 PM
  3. Help with method. Finding minimum value in Array
    By richardman54 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2013, 11:13 PM
  4. method not passing across actionlistener interface
    By flamewolf393 in forum AWT / Java Swing
    Replies: 9
    Last Post: November 16th, 2011, 07:16 AM
  5. Error when adding ActionListener to JButton
    By grimrader22 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 10th, 2011, 06:53 AM

Tags for this Thread