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 4 of 4

Thread: I get this error when compiling my program

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I get this error when compiling my program

    code = Java

    // ButtonFrame.java
    // Creating JButton

    package btest.ButtonFrame;

    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;

    public class ButtonFrame extends JFrame{
    private JButton plainJButton; // button with just text
    private JButton fancyJButton; // button with icons

    // ButtonFrame adds JButtons to JFrame
    public ButtonFrame(){
    super("Testing Buttons");
    setLayout(new FlowLayout()); // set frame layout

    plainJButton = new JButton("Plain Button"); // button with text
    add(plainJButton); // add plainJButton to JFrame

    Icon bug1 = new ImageIcon(getClass().getResource("HD.png"));
    Icon bug2 = new ImageIcon(getClass().getResource("Apple.png"));
    fancyJButton = new JButton("Fancy Button", bug1); // set image
    fancyJButton.setRolloverIcon(bug2); // set rollover image
    add(fancyJButton); // add fancyJButto to JFrame

    // create new ButtonHandler for button event handling
    ButtonHandler handler = new ButtonHandler();
    fancyJButton.addActionListener(handler);
    plainJButton.addActionListener(handler);
    } // end ButtonFrame constructor

    // inner class for button event handling
    private class ButtonHandler implements ActionListener{ // ERROR */
    // handle button event
    public void actionPerfomed(ActionEvent event){
    JOptionPane.showMessageDialog(ButtonFrame.this, String.format("You pressed: %s",
    event.getActionCommand()));
    }
    }
    }

    /code







    code = Java

    //ButtonTest.java
    // Testing ButtonFrame

    package btest;
    import btest.ButtonFrame.ButtonFrame;
    import javax.swing.JFrame;

    public class BTest {

    public static void main(String[] args) {
    ButtonFrame buttonFrame = new ButtonFrame(); // create button frame
    buttonFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    buttonFrame.setSize(275, 110); // set frame size
    buttonFrame.setVisible(true); // display frame
    }
    }
    /code
    Last edited by klinston69; April 29th, 2014 at 10:02 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: trying to make my event handler work plss help me

    Pretty impressive try at imitating what highlight tags would do for you. Instead of doing all that work, please read this post and note the first item about using code tags. Code tags preserve formatting and do some highlighting, but highlight tags do a nicer job.

    As for your question, please describe "working" versus "not working." What help do you need? Ask specific questions, give examples if possible.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: trying to make my event handler work plss help me

    Hi
    am trying to get my button handler to work but ends up getting this error message
    "ButtonFrame.ButtonHandler is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener"



    [highlight=Java]
    // ButtonFrame.java
    // Creating JButton
    package btest.ButtonFrame;
     
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
     
    public class ButtonFrame extends JFrame{
       private JButton plainJButton; // button with just text
       private JButton fancyJButton; // button with icons
     
       // ButtonFrame adds JButtons to JFrame
       public ButtonFrame(){
          super("Testing Buttons");
          setLayout(new FlowLayout()); // set frame layout
     
          plainJButton = new JButton("Plain Button"); // button with text
          add(plainJButton); // add plainJButton to JFrame
     
          Icon bug1 = new ImageIcon(getClass().getResource("HD.png"));
          Icon bug2 = new ImageIcon(getClass().getResource("Apple.png"));
          fancyJButton = new JButton("Fancy Button", bug1); // set image
          fancyJButton.setRolloverIcon(bug2); // set rollover image
          add(fancyJButton); // add fancyJButto to JFrame
     
          // create new ButtonHandler for button event handling
          ButtonHandler handler = new ButtonHandler();
          fancyJButton.addActionListener(handler);
          plainJButton.addActionListener(handler);
       } // end ButtonFrame constructor
     
       // inner class for button event handling
       private class ButtonHandler implements ActionListener{ // THE ERROR IS ON THIS LINE
          // handle button event
          public void actionPerfomed(ActionEvent event){
             JOptionPane.showMessageDialog(ButtonFrame.this, String.format("You pressed: %s",
                     event.getActionCommand()));
          }
       }
    }
     
     
     
     
     
    //ButtonTest.java
    // Testing ButtonFrame
    package btest;
    import btest.ButtonFrame.ButtonFrame;
    import javax.swing.JFrame;
     
    public class BTest {
     
       public static void main(String[] args) {
          ButtonFrame buttonFrame = new ButtonFrame(); // create button frame
          buttonFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          buttonFrame.setSize(275, 110); // set frame size
          buttonFrame.setVisible(true); // display frame
       }
    }
     
     
     
     
    [/highlight]

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I get this error when compiling my program

    does not override abstract method actionPerformed(ActionEvent)
    The compiler can not find a method matching that shown in the error message. That method is required to be defined in the class because it implements ActionListener.

    Check the spelling.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Event Handler Question
    By shep in forum Java Theory & Questions
    Replies: 5
    Last Post: April 10th, 2014, 02:39 PM
  2. Event Handler For a JTextField
    By JamesdTurnham in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 17th, 2013, 06:16 PM
  3. JButton event handler
    By gkelly642 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 3rd, 2013, 09:01 PM
  4. Separate Event Handler Class
    By beer-in-box in forum AWT / Java Swing
    Replies: 2
    Last Post: April 1st, 2013, 09:19 AM
  5. JButton event handler
    By Jsri in forum AWT / Java Swing
    Replies: 1
    Last Post: October 25th, 2011, 07:02 AM