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

Thread: help with abstract and nonabstract action listner

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default help with abstract and nonabstract action listner

    import javax.swing.JFrame;
    import java.awt.FlowLayout;
    import java.awt.Color;
    import javafx.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class FrameAndButton extends JFrame implements ActionListener {
     
        public static void main(String args[]) {
           FrameAndButton fnb = new FrameAndButton();
            fnb.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            fnb.setSize(500, 300);
            fnb.setResizable(false);
            fnb.setTitle("Frame and Button");
            fnb.getContentPane().setBackground(Color.white);
            fnb.setLocationRelativeTo(null);//to put the frame in the middle of the window,before setvislible()
            fnb.getContentPane().setLayout(new FlowLayout());//wont overlap the button to whole frame
            JButton btn = new JButton();
            btn.setBackground(Color.white);
            btn.setText("Java Code trying");
            fnb.add(btn);
            fnb.setVisible(true);
            btn.addActionListener(this);
        }
    //buttonAction();
     
        public FrameAndButton() {
            constructFrame();
        }//FrameAndButton constructor
     
        public final void constructFrame() {
     
     
        }
                public void actionPerformed(ActionEvent e) {
                    JFrame frame2 = new JFrame("Your Stocks");
                    frame2.setVisible(true);
                    frame2.setSize(600, 600);
                    JLabel label = new JLabel("Your Personal Stocks");
                    JPanel panel = new JPanel();
                    frame2.add(panel);
                    panel.add(label);
                }
     
    //fnb.pack();// autometically addjest the frame size put it at last after adding all butns etc..
        // constructFrame method
    }

    Dear people can you please help me with this code keeps telling me
    non abstract method cannot be override by the abstract method.
    but i think am doing it right way of course its wrong.

  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: help with abstract and nonabstract action listner

    The error message I see when I attempt to compile your code is

    FrameAndButton.java:10: error: FrameAndButton is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
    public class FrameAndButton extends JFrame implements ActionListener {
           ^

    (Note: it is always a good idea to copy and post the exact compiler message as you see it. That way everyone knows exactly what is happening and can, most easily, explain it).

    The problem here is that the FrameAndButton class is declared as implementing the ActionListener interface, but it does not define an actionPerformed(ActionEvent) method. I know you have a method of that name ... but it is using the wrong sort of ActionEvent.

    It turns out there are more than one class of that name in Java. Check the ActionListener documentation to see what ActionEvent you should be using. You can do that by clicking on (or hovering over) "ActionEvent" where it is mentioned in the "Method detail" section. Then make sure you are importing the correct ActionEvent class.

  3. #3
    Junior Member
    Join Date
    Feb 2018
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: help with abstract and nonabstract action listner

    thanks for correcting me and compiling it.
    can anyone please correct the error.

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: help with abstract and nonabstract action listner

    Did you check the ActionListener documentation? And, if so, were you able to locate the full name of ActionEvent class (including the package of which it's part)?

  5. #5
    Junior Member
    Join Date
    Feb 2018
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: help with abstract and nonabstract action listner

    be honest with you i did not get that that that is too mcuh for me am new to java but i will keep trying it. it will be great if you just fix my code this time thats all my code is.

Similar Threads

  1. Action Listeners within and Action Listener on Panels
    By avidlearner in forum AWT / Java Swing
    Replies: 3
    Last Post: April 8th, 2014, 12:21 PM
  2. [SOLVED] Anonymous inner class with Action Listener and Abstract Action
    By shakes6791 in forum Java Theory & Questions
    Replies: 5
    Last Post: November 13th, 2013, 03:52 PM
  3. Replies: 1
    Last Post: May 20th, 2013, 01:19 AM
  4. [SOLVED] Abstract method in a non-abstract class
    By bassie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 2nd, 2012, 11:27 AM
  5. GUI error: is not abstract and does not override abstract method
    By djl1990 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 21st, 2011, 01:26 PM