Abstract button

Interface.java:61: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (Interface).....
if after compile i got this message, what does it mean and what should i do for it? thanks

Do you have the linepublic class Interface extends ... implements ActionListener[, ...]?
Kind regards,
  Levi

Similar Messages

  • FocusListener not working for abstract button

    hi,
    FocusListener is not working for abstract button...
    Is there any other method which work similar to focusGained()...
    I think isFocusable() do that... Iam not sure about it.. Could anyone explain about it.
    It is needed very urgently.
    thanks in advance,
    regards,
    Deepa Raghuraman

    for all JComponent you have the hasFocus() method....

  • Help-I Need to hold a Abstract button pressed

    hi,
    I have captured a button instance from abbot. I need to hold the button pressed for 2 seconds without releasing.
    I need to know, how to do it?
    Pressing the button for more than 2 seconds without releasing will popup a menu.. i need to get the instance of the menu too...
    How can i do that, either through Java or with Abbot.
    Thanks,
    With Regards,
    Priyaa.

    what the heck is Abbot?I thought everyone knew about [url http://www.jahozafat.com/TV_Shows/Abbott_And_Costello/hey_abbott.wav]Abbot.

  • Using area of image as button (active area)

    Hello
    I have image (jpg) that is displayed in applet and I'd like to change portion of it into let's say button. I would see image as I did before but when I move mouse over this button area something would happen (listener).
    Can I do it?. If yes, can this button have any shape I want?.
    Cheers

    yes and yes.
    the easy way is this:
    put the image in one component, and put the button over top of it. there are a couple ways to do this:
    subclass JPanel or JComponent (different people have different preferences here) and override the paint component method to paint the image.
    THEN, Override either abstract button or JButton (again, different camps think differently here), and override the paint method (not the paint component method) to do absolutely NOTHING.
    add your new button to the panel/component and voila. You have an invisible button overtop of your image (note, the visible property of the button will need to be true for it to respond, but you can choose not to paint the button, even if visible is true).
    if you want to use any shape, you must also override the contains method of the button. I find the easiest way to do this is to create a java.awt.Shape or java.awt.Area object, and use the default implemnetation of contains of those objects.
    Another solution, rather than painting the image in a JPanel or JComopnent, use the image as the icon of a JLabel, and put both the label and button in the same container, using either a null layout, and set the bounds yourself, or using a layout manager like stack layout which places all components in the same position, with a Z-ordering.
    - Adam

  • Button State Affected by Windows XP Display Settings

    I have a reference to a 3rd party class that extends JToolBar. I am trying to set one of the buttons in this
    JToolBar to "pressed." I know the action class for the specific button I am looking for so I just iterate across
    all the (abstract) buttons in the toolbar's button group. (See code below.) When I find the button whose
    action is the one I am looking for I call setSelected() on the button.
    Here is where it gets wierd.....
    I am running Windows XP and, if I change the Appearance Windows and Buttons mode** to
    "Windows XP" style the code works fine (the button gets depressed programatically). However,
    if I change the mode to "Windows Classic" style the button no longer gets depressed.
    Any ideas as to how the windows mode could be affecting my code???
    Thank you,
    Michelle
    ** right click on the desktop and select "Properties" go to the "Appearance" panel and select from
    the "Windows and Buttons" pulldown menu.
    Enumeration buttons = mapToolBar.getButtonGroup().getElements();
    while (buttons.hasMoreElements()) {
    AbstractButton button = (AbstractButton) buttons.nextElement();
    Action action = (Action) button.getAction();
    if (action == MyButtonAction) {
    button.setSelected(true);
    break;
    }

    You might want to check with third party who developed the toolbar extension.
    I would also try a small test program using only out-of-the-box Swing JToolBar to see if you get the same result.
    Hope that helps
    DB

  • Listeners in a different class??

    Hi ,
    Is it possible to listen the events of "Class A" in "Class B"?? I have certain events that raise in "Class A". I need to listen this in "Class B". I believe there is a descent way of doing this in Swing. Can anyone share ??
    Thanks in Advance..
    regards
    Rajesh rapaka.

    I guess u are talking about something like this :
    AbstractButton button = new JButton("OK");
        button.addActionListener(new MyActionListener());
        public class MyActionListener implements ActionListener {
            public void actionPerformed(ActionEvent evt) {
                // Determine which abstract button fired the event.
                AbstractButton button = (AbstractButton)evt.getSource();
        }But what I am looking for is something different. where the conditions are like this :
    example:
    public class Frm extends JFrame{
    public Frm(){
    ToolBar mb = new ToolBar();
    add(mb);
    }Class ToolBar:
    public class ToolBar extends JToolBar implements ActionListener{
    public ToolBar(){
    JButton jb = new JButton("tstButton");
    jb.addActionListener(this);
    public void actionPerformed(ActionEvent e){
    System.out.Println("event raised");
    }The ToolBar class is initialised and added on the frame. Which has buttons on it which raise events. How can I get these raised events in Frm class?? I want to have an ActionListener in Frm class that can listen to events raised even in MenuBar.
    is this possible ? and how ?
    thank for ur time in advance....
    regs,
    Rajesh rapaka.

  • Factory

    Hi guys,
    I was reading a book when I came accross to an:
    public abstract interface xpto()being called a factory.
    But how can this class be called a factory? I have been lintening this word for a while, but I never cared much about it, because like the name says, it was a factoring class. I though about them as classes full of static methods which would eventually return instances of given classes.
    Other thing, does it make any sence to have an abstract interface at all?
    Thanks in advance,
    MeTitus

    I think I am not undertanding this factory stuff at all..
    The class I am speaking about is this one:
    ConnectionPoolDataSourceThis what I usually do:
    public abstract class GUIFactory {
       public static GUIFactory getFactory() {
            int sys = readFromConfigFile("OS_TYPE");
            if (sys == 0) {
                return(new WinFactory());
            } else {
                return(new OSXFactory());
       public abstract Button createButton();
    }But in this case the Connect.... class doesn't have any static methods that can return instances, how can it be called a factory if it can't return any instances at all.
    MeTitus

  • Finding out a Checkbox state

    How do I find out whether a checkbox is ticked or not
    like
    If Checkbox.ticked
                  ticked = true
           }

    Cyanide2007 wrote:
    I am very new to this I do not know what an abstract button isLook at the top of the API page for JCheckBox (someone has helpfully already provided the link):
    java.lang.Object
      extended by java.awt.Component
          extended by java.awt.Container
              extended by javax.swing.JComponent
                  extended by javax.swing.AbstractButton
                      extended by javax.swing.JToggleButton
                          extended by javax.swing.JCheckBoxAbstractButton is a superclass of JCheckBox

  • Partial modality

    Hi,
    My project has a new requirement. We have two JFrames as part of the application, say Frame1 and Frame2. The requirement states that when any dialog is displayed via some interaction in Frame1, the dialog should be modal for Frame1, but not for Frame2. Therefore, while dialog 1 is displaying due to some click in Frame1, I should still be able to carry out some interactions in Frame2.
    Is this even possible??? I have tried looking for modality on the site, but all I get is 'A modal dialog is one which blocks input to all other toplevel windows in the application, except for any windows created with the dialog as their owner'. Now does top level mean parent of dialog and all such ancestors, or all higher level windows, including all JFrames?
    Any help in this matter appreciated.
    Shefali.

    Hi Tom,
    You're welcome to the dukes!!! Anyways, a small problem. I used the code from one of the javatips, and implemented the following code. If you have the time, I'd really appreciate your helping me find out what's wrong...
    The basic idea is that I have two frames, Frame1 and Frame2. Each has one button for launching a dialog, one checkbox, and one exit button. When a dialog is launched from one frame, all inputs to that frame should be blocked, but the other frame should stay unaffected. When the dialog is closed, the first frame also starts getting all inputs.
    I am putting the following files below:
    - Blocker.java: the class derived from EventQueue. This one basically maintains a vector of restricted components, and assumes that any component in this vector is not supposed to receive any inputs. It is the duty of the various dialogs to add its owner (and contained components) to this vector on show, and remove the owner from the vector on hide/dispose.
    - Test2.java: the main; creates two frames, and adds the action listeners etc.
    - MyDialog.java: the dialog to be launched on clicking the button in the frame (also supports same dialog launched on clicking button in dialog, as this is also a requirement, but does not currently pertain to my problem).
    // Blocker.java
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class Blocker extends EventQueue
        private Vector m_oVectRestrictedComponents;
        private EventQueue m_oSystemQ =
                Toolkit.getDefaultToolkit().getSystemEventQueue();
        private static Blocker m_oInstance = null;
        public static synchronized Blocker Instance()
            if(m_oInstance == null)
                m_oInstance = new Blocker();
            return m_oInstance;
        private Blocker()
            m_oVectRestrictedComponents = new Vector();
             m_oSystemQ.push(this);
        public void reset()
             m_oVectRestrictedComponents.removeAllElements();
        public void addRestrictedComponent(final Component oComp)
            if(oComp == null)
                 return;
             addChildComponents(oComp);
         public void removeRestrictedComponent(final Component oComp)
              if(oComp == null || m_oVectRestrictedComponents.size() == 0)
                   return;
              removeChildComponents(oComp);
          * Add component to list of restricted components. If a JComponent, set its
          * request focus enabled false, and if an abstract button, set its focus
          * painted false. If a container, do the same for all its contained
          * components.
          * @param oComp
        private void addChildComponents(final Component oComp)
            m_oVectRestrictedComponents.add(oComp);
             if(oComp instanceof JComponent)
                 ((JComponent)oComp).setRequestFocusEnabled(false);
             if(oComp instanceof AbstractButton)
                 ((AbstractButton)oComp).setFocusPainted(false);
            final int iCompCount = ((Container)oComp).getComponentCount();
            if(iCompCount != 0)
                for(int i = 0; i < iCompCount; i++)
                    addChildComponents(((Container)oComp).getComponent(i));
          * Remove component from list of restricted components. If a Jcomponent, set
          * its request focus enabled true, and if an abstract button, its set focus
          * painted true. If component is a container, do the same for all its
          * contained components.
          * @param oComp
         private void removeChildComponents(final Component oComp)
             m_oVectRestrictedComponents.remove(oComp);
              if(oComp instanceof JComponent)
                  ((JComponent)oComp).setRequestFocusEnabled(true);
              if(oComp instanceof AbstractButton)
                  ((AbstractButton)oComp).setFocusPainted(true);
              final int iCompCount = ((Container)oComp).getComponentCount();
              if(iCompCount != 0)
                  for(int i = 0; i < iCompCount; i++)
                      removeChildComponents(((Container)oComp).getComponent(i));
        private Component getSource(final AWTEvent event)
            Component source = null;
            // each of these five MouseEvents will still be valid (regardless
            // of their source), so we still want to process them.
            if((event instanceof MouseEvent) &&
                    (event.getID() != MouseEvent.MOUSE_DRAGGED) &&
                    (event.getID() != MouseEvent.MOUSE_ENTERED) &&
                    (event.getID() != MouseEvent.MOUSE_EXITED) &&
                    (event.getID() != MouseEvent.MOUSE_MOVED) &&
                    (event.getID() != MouseEvent.MOUSE_RELEASED))
                final MouseEvent mouseEvent = (MouseEvent)event;
                source = SwingUtilities.getDeepestComponentAt(
                        mouseEvent.getComponent(),
                        mouseEvent.getX(),
                        mouseEvent.getY());
            else if(event instanceof KeyEvent &&
                    event.getSource() instanceof Component)
                source = SwingUtilities.findFocusOwner(
                        (Component)(event.getSource()));
            return source;
        private boolean isSourceBlocked(final Component oSource)
            boolean blocked = false;
            if((m_oVectRestrictedComponents.size() != 0) && (oSource != null))
                final int iNumRestrictedComponents = m_oVectRestrictedComponents.size();
                int i = 0;
                while(i < iNumRestrictedComponents &&
                        (m_oVectRestrictedComponents.get(i).equals(oSource) == false))
                    i++;
                blocked = i < iNumRestrictedComponents;
            return blocked;
        protected void dispatchEvent(final AWTEvent event)
             System.out.println();
             System.out.println(event);
             // getSource is a private helper method
             final boolean blocked = isSourceBlocked(getSource(event));
            if(blocked &&
                    (event.getID() == MouseEvent.MOUSE_CLICKED ||
                    event.getID() == MouseEvent.MOUSE_PRESSED))
                Toolkit.getDefaultToolkit().beep();
            else if(blocked &&
                    event instanceof KeyEvent &&
                    event.getSource() instanceof Component)
                final DefaultFocusManager dfm = new DefaultFocusManager();
                dfm.getCurrentManager();
                Component currentFocusOwner = getSource(event);
                boolean focusNotFound = true;
                do
                    dfm.focusNextComponent(currentFocusOwner);
                    currentFocusOwner = SwingUtilities.findFocusOwner(
                            (Component)event.getSource());
                    if(currentFocusOwner instanceof JComponent)
                        focusNotFound =
                                (((JComponent)currentFocusOwner).isRequestFocusEnabled() == false);
                while(focusNotFound);
            else
                super.dispatchEvent(event);
    // Test2.java
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    * This Test class demonstrates how the Blocker is used.
    * The Test opens a new JFrame object containing five different
    * components.  The button labeled "Block" will block "Button"
    * and "CheckBox".  The button labeled "Unblock" will make "Button"
    * and "CheckBox" accessible to the user.
    * "Button" and "CheckBox" have no attached functionality.
    public class Test2
         private JFrame m_oFrame1;
         private JFrame m_oFrame2;
         private JButton m_oDisplayDialog1;
         private JButton m_oDisplayDialog2;
         public Test2()
              final WindowClosingAdapter oWindowAdapter = new WindowClosingAdapter();
              final DisplayDialogActionListener oDisplayDialogActionListener =
                      new DisplayDialogActionListener();
              final ExitListener oExitListener = new ExitListener();
              m_oFrame1 = new JFrame();
              m_oFrame1.setTitle("Blocker Test1");
              m_oFrame1.addWindowListener(oWindowAdapter);
              m_oFrame1.setSize(400, 200);
              m_oDisplayDialog1 = new JButton("Button1");
              m_oDisplayDialog1.setMnemonic('1');
              m_oDisplayDialog1.addActionListener(oDisplayDialogActionListener);
              final JCheckBox checkBox = new JCheckBox("CheckBox1");
              final JButton exitButton = new JButton("Exit1");
              exitButton.addActionListener(oExitListener);
              Container contentPane = m_oFrame1.getContentPane();
              contentPane.setLayout(new FlowLayout());
              contentPane.add(m_oDisplayDialog1);
              contentPane.add(checkBox);
              contentPane.add(exitButton);
              m_oFrame1.setVisible(true);
              m_oFrame2 = new JFrame();
              m_oFrame2.setTitle("Blocker Test2");
              m_oFrame2.addWindowListener(oWindowAdapter);
              m_oFrame2.setSize(400, 200);
              m_oDisplayDialog2 = new JButton("Button2");
              m_oDisplayDialog2.setMnemonic('2');
              m_oDisplayDialog2.addActionListener(oDisplayDialogActionListener);
              final JCheckBox cb = new JCheckBox("CheckBox2");
              final JButton exitbutton2 = new JButton("Exit2");
              exitbutton2.addActionListener(oExitListener);
              contentPane = m_oFrame2.getContentPane();
              contentPane.setLayout(new FlowLayout());
              contentPane.add(m_oDisplayDialog2);
              contentPane.add(cb);
              contentPane.add(exitbutton2);
              m_oFrame2.setVisible(true);
        public static void main(String[] argv)
             new Test2();
             Blocker.Instance();
         private class DisplayDialogActionListener implements ActionListener
              public void actionPerformed(final ActionEvent e)
                   final Object oSource = e.getSource();
                   JFrame oParent = null;
                   if(oSource.equals(m_oDisplayDialog1))
                        oParent = m_oFrame1;
                   else if(oSource.equals(m_oDisplayDialog2))
                        oParent = m_oFrame2;
                   if(oParent == null)
                        return;
                   final MyDialog oDialog = new MyDialog(oParent);
                   oDialog.show();
         private class WindowClosingAdapter extends WindowAdapter
               * Invoked when a window has been closed.
              public void windowClosed(WindowEvent e)
                   System.exit(0);
         private class ExitListener implements ActionListener
              public void actionPerformed(final ActionEvent e)
                   System.exit(0);
    // MyDialog.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    public class MyDialog extends JDialog
         private static int INITIALIZER = 0;
         private final Blocker m_oBlocker = Blocker.Instance();
         public MyDialog(final Frame owner) throws HeadlessException
              super(owner, "Frame Parent" + INITIALIZER);
              INITIALIZER++;
              initializeDialog();
         public MyDialog(final Dialog owner) throws HeadlessException
              super(owner, "Dialog Parent" + INITIALIZER);
              INITIALIZER++;
              initializeDialog();
         private void initializeDialog()
              setSize(200, 100);
              final JButton oDoNothing = new JButton("Do Nothing");
              oDoNothing.addActionListener(new DisplayDialogActionListener());
              final JButton oCloseDialog = new JButton("Close");
              oCloseDialog.addActionListener(new ActionListener()
                   public void actionPerformed(final ActionEvent e)
                        MyDialog.this.dispose();
              final Container oContentPane = getContentPane();
              oContentPane.setLayout(new FlowLayout());
              oContentPane.add(oDoNothing);
              oContentPane.add(oCloseDialog);
         public void show()
              System.out.println(getTitle() + " show called");
              super.show();
              System.out.println(getTitle() + " adding owner to restricted list");
              m_oBlocker.addRestrictedComponent(getOwner());
          * Hides the Dialog and then causes show() to return if it is currently
          * blocked.
         public void hide()
              System.out.println(getTitle() + " removing owner from restricted list");
              m_oBlocker.removeRestrictedComponent(getOwner());
              System.out.println(getTitle() + " hide called");
              super.hide();
          * Disposes the Dialog and then causes show() to return if it is currently
          * blocked.
         public void dispose()
              System.out.println(getTitle() + " removing owner from restricted list");
              m_oBlocker.removeRestrictedComponent(getOwner());
              System.out.println(getTitle() + " dispose called");
              super.dispose();
         private class DisplayDialogActionListener implements ActionListener
              public void actionPerformed(final ActionEvent e)
                   final MyDialog oDialog = new MyDialog(MyDialog.this);
                   oDialog.show();
    }Now, my problem is that when i try to display the dialog using a mouse click on the button, there is never any problem, neither does there appear to be a problem if the focus is on the button and I press space/enter. But if there is a mnemonic set, and I use that (like Alt-1), then SOMETIMES, the entire application hangs. I am stumped as to why this is happening... Any help AT ALL is seriously appreciated.
    Thanks,
    Shefali.

  • How would I create buttons states for MCs I am creating abstract MCs

    I am creating a generic website that would have abstract MCs that would load jpg or TXT fields for the user interface to allow for fast updates to the site. The MCs that would make up the user interface would be empty and load things into it using XML or PHP later on. How would I create button states for the user interface MCs.  I started creating a function for every MC button state but I thought there might be a more efficient way.
    would creating a array help in this case?
    and is using URLRequest the way to link to pages with in a movie well the flash movie that is the site it's self?
    /*---------------------------- THE START OF MY ACTION SCRIPT ------------------------------*/
    var waywardLogo_mc:MovieClip = new MovieClip;
    var theCollection_mc:MovieClip = new MovieClip;
    var newsPage_mc:MovieClip = new MovieClip;
    var whatthe#$@!doyouwant!?_mc:MovieClip = new MovieClip;
    /*---------------------------- onOver ------------------------------*/
    waywardLogo_mc.addEventListener(MouseEvent.ROLL_OVER,onOver);
    theCollection_mc.addEventListener(MouseEvent.ROLL_OVER,onOver);
    newspage_mc.addEventListener(MouseEvent.ROLL_OVER,onOver);
    whatthe#$@!doyouwant!?_mc.addEventListener(MouseEvent.ROLL_OVER,onOver);
    /*---------------------------- onOut ------------------------------*/
    waywardLogo_mc.addEventListener(MouseEvent.ROLL_OUT,onOut);
    theCollection_mc.addEventListener(MouseEvent.ROLL_OUT,onOut);
    newspage_mc.addEventListener(MouseEvent.ROLL_OUT,onOut);
    whatthe#$@!doyouwant!?_mc.addEventListener(MouseEvent.ROLL_OUT,onOut);
    /*---------------------------- onClick ------------------------------*/
    waywardLogo_mc.addEventListener(MouseEvent.CLICK,onClick);
    theCollection_mc.addEventListener(MouseEvent.CLICK,onClick);
    newspage_mc.addEventListener(MouseEvent.CLICK,onClick);
    whatthe#$@!doyouwant!?_mc.addEventListener(MouseEvent.CLICK,onClick);
    function onOver(event:MouseEvent):void
    event.target.alpha = .5;
    function onOut(event:MouseEvent):void
    event.target.alpha = 1;
    function onClick(event:MouseEvent):void
    event.target.URLRequest("");
    /*---------------------------- onover, onOut, onClick buttonModes ------------------------------*/
    waywardLogo_mc.buttonMode = true;
    theCollection_mc.buttonMode = true;
    newspage_mc.buttonMode = true;
    whatthe#$@!doyouwant!?_mc.buttonMode = true;

    click insert/new symbol, tick movieclip, assign a name, tick export for actionscript and in the class textfield enter a name (say ButtonClass) and click ok.
    attached to the first frame of your new movieclip, type stop() in the actions panel.  put whatever graphic you want on-stage for your button's up stage.  create another keyframe, label it "over" and put whatever graphic you want for button's over state on-stage.
    in a layer above those graphics, you'll probably want to add a dynamic textfield so each of your buttons can have different text.  assign the textfield and instance name (say tf) and extend its timeline to the last frame of your movieclip button.
    then when you want to create a button, on your timeline you can use:
    var b:ButtonClass=new ButtonClass();  // these two lines need to be entered for each button
    buttonhandlerF(b,someX,someY);
    //-------code between dotted lines only needs to be entered once no matter how many buttons you add --------------------
    function buttonhandlerF(b:ButtonClass,x:Number,y:Number){
    b.addEventListener(MouseEvent.MOUSE_OVER,overF);
    b.addEventListener(MouseEVent.MOUSE_OUT,outF);
    b.x=x
    b.y=y
    addChild(b);
    function overF(e:MouseEvent){
    e.currentTarget.gotoAndStop("over");
    function outF(e:MouseEvent){
    e.currentTarget.gotoAndStop(1);
    //-------code between dotted lines only needs to be entered once --------------------
    // you'll also want to create a click listener and listener function
    the code between the dotted lines is amenable to being added to a ButtonClass.as class file if want to expand your capabilities.

  • Multiple CSV exports from the one button or pl/sql procedure?

    I need to have multiple csv exports from the one press of a button. The easiest way I found to do this is it to use javascript to popup three windows, each as a CSV link. This is a bit ugly though, and leaves the browser popup windows open when the file has been downloaded.
    I guess I could also make a solution based on branching, but I think that would be difficult to maintain and reeks of bad design (im not a fan of this spagetti GOTO style code!).
    I implemented Scott's custom CSV as found here: http://spendolini.blogspot.com/2006/04/custom-export-to-csv.html
    However I would like to know if its possible to download more than one file using this method. I could not work out how to do this .
    Has anyone got any ideas? Simply repeating the code puts the second table into the original csv file. Is there a way to 'reset' the htp writer or smoething?
    Any help greatly appreciated,
    Alex

    Sorry for the confusion - I guess I mean its easy in .NET because you can simply compress files together and then send 1 zip file down as the response. See http://www.developer.com/net/net/article.php/11087_3510026_2 for details.
    I guess I could ask how to do this in APEX - but it seems to me that my original wording addresses the concept at a much more abstract level. I may not find the best solution for my problem if I just asked 'how can I dynamically zip together three tables as seperate files and send them to the client?'. I also suspect that this method is not possible in APEX without custom packages. Please prove me wrong!
    I guess even if I could find some kind of javascript that didnt open a new window, but was a direct download to the CSV, that would be a good compromise. At the moment when you click on the link, three windows come up and stay blank until the files are ready for downloading. Then after the files have been downloaded the windows must be shut manually. Yes, I could use javascript to make the windows 1x1 pixel perhaps, and then shut them after a predetermined timeframe - but this is hardly an elegant solution!
    Thanks for your responses.

  • ..is not abstract and does not override abstract method..

    Hello,
    I've been creating a GUI from scratch, up to now, i have managed to successfully compile the code which forms the window, and a JMenu bar. I now need to add buttons, and for this i need to use an ActionListener, but when i put "implements ActionListener" at the end of "public class TestCode extends JFrame", i recieve the above error message (abstract..). I've looked at recent posts and have come across a post that says adding "actionPerformed(java.awt.event.ActionEvent e)" to the class will resolve the issue. When i add that, i recieve a compile error message saying to add '{' after actionPerformed. I've done this however it still does not compile. Can anyone point me in the right direction please?
    Thanks
    George
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JMenu;
    import javax.swing.JLabel;
    import javax.swing.JMenuItem;
    import javax.swing.JButton;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.ImageIcon;
    import javax.swing.AbstractButton;
    import javax.swing.JFrame;
    import java.awt.event.KeyEvent;
    import java.util.*;
    public class TestCode extends JFrame  {
        private static void createAndShowGUI() {
         JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame frame = new JFrame("Robot Control Station");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         JMenuBar menuBar = new JMenuBar();
         JMenu fileMenu = new JMenu("Exit");
         fileMenu.setMnemonic(KeyEvent.VK_F);
         menuBar.add(fileMenu);
            JLabel emptyLabel = new JLabel("");
            emptyLabel.setPreferredSize(new Dimension(750, 750));
            frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
         JMenuItem newMenuItem = new JMenuItem("Exit Program", KeyEvent.VK_N);
         fileMenu.add(newMenuItem);
         frame.setJMenuBar(menuBar);
         frame.setVisible(true);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
           //forward button
         JButton forward = new JButton("Forward");
         forward.setMnemonic(KeyEvent.VK_D);
            forward.setActionCommand("disable");
         forward.setToolTipText("Click this button to make the robot go forward.");
         forward.add(forward);
         frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
         

    thanks for the help,
    i read the tutorial, and have starte dto understand how to use action listeners, but i seem to have stumbled to another problem, it seems that i dont fully undertsand how to use ActioListeners, and i cant see mto see what i'm doing wrong.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JMenu;
    import javax.swing.JLabel;
    import javax.swing.JMenuItem;
    import javax.swing.JButton;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.ImageIcon;
    import javax.swing.AbstractButton;
    import javax.swing.JFrame;
    import java.awt.event.KeyEvent;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.*;
    public class TestCode extends JFrame implements WindowListener,ActionListener {
         public void actionPerformed(ActionEvent e) {
         forward = new JButton("Forward");
         frame.setLayout(null);
         forward.setMnemonic(KeyEvent.VK_D);
         forward.setActionCommand("Forward");
         forward.setToolTipText("Click this button to make the robot go forward!");
         add(forward);
         addActionListener(this);
         frame.add(forward);     
         JFrame frame;
         JButton forward;
         frame.addActionListener(this);
         private static void createAndShowGUI() {
         JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame frame = new JFrame("Robot Control Station");
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.addWindowListener(this);
         frame.pack();
            frame.setVisible(true);
         //JMenuBar createMenuBar;
         JMenuBar menuBar = new JMenuBar();
         JMenu fileMenu = new JMenu("Exit");
         fileMenu.setMnemonic(KeyEvent.VK_F);
         menuBar.add(fileMenu);
            JLabel emptyLabel = new JLabel("");
            emptyLabel.setPreferredSize(new Dimension(750, 750));
            frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
         JMenuItem newMenuItem = new JMenuItem("Exit Program", KeyEvent.VK_N);
         fileMenu.add(newMenuItem);
         frame.setJMenuBar(menuBar);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
         it points me to line 22 which is frame.addActionListener(this); , it tells me that an identifier is expected, and it is an illegal start of type. I can't get my head round it. Can anyone turn me to the right direction again please?

  • Is not abstract and does not override abstract method actionPerformed

    I dont how to corr. Please help!! and thank you very much!!
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class test extends JFrame implements ActionListener, ItemListener
              private CenterPanel centerPanel;
              private QuestionPanel questionPanel;
              private ButtonPanel buttonPanel;
              private ResponsePanel responsePanel;
              private JButton b1,b2,b3,b4,b5;               //Create five references to Jbutton instances
         private JTextField t1,t2,t3,t4,t5;          //Create five references to JTextField instances
              private JLabel label1;                    //Create one references to JLabel instances
              private JRadioButton q1,q2,q3;               //Create three references to JRadioButton instances
              private ButtonGroup radioGroup;               //Create one references to Button Group instances
              private int que1[] = new int[5];           //Create int[4] Array
              private int que2[] = new int[5];
              private int que3[] = new int[5];
              private String temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10,
                        temp11, temp12, temp13, temp14, temp15;
    public test (String header)
              super(header);
              Container container = getContentPane();
              label1 = new JLabel ("PLease click on your response to ");     
              q1 = new JRadioButton("I understand most of the content of this subject",true);
              add(q1);
              q2 = new JRadioButton("I see the relevance of the subject to my degree",false);
              add(q2);
              q3 = new JRadioButton("The workload in this subject is appropriate",false);
              add(q3);
              radioGroup = new ButtonGroup();               //JRadioButton belong to ButtonGroup
              radioGroup.add(q1);
              radioGroup.add(q2);
              radioGroup.add(q3);
              JPanel buttonPanel = new JPanel();
              JPanel responsePanel = new JPanel();
              JPanel questionPanel = new JPanel();
              JPanel centerPanel = new JPanel();
              b1 = new JButton ("Strongly DISAGREE");          //Instantiate JButton with text
              b1.addActionListener (this);               //Register JButtons to receive events
              b2 = new JButton ("DISAGREE");
              b2.addActionListener (this);
              b3 = new JButton ("Neither AGREE or DISAGREE");
              b3.addActionListener (this);
              b4 = new JButton ("AGREE");
              b4.addActionListener (this);
              b5 = new JButton ("Strongly AGREE");
              b5.addActionListener (this);
              buttonPanel.setLayout(new GridLayout(5,1));
              buttonPanel.add(b1);
              buttonPanel.add(b2);
              buttonPanel.add(b3);
              buttonPanel.add(b4);
              buttonPanel.add(b5);
              t1 = new JTextField ("0",3);               //JTextField contains empty string
              t2 = new JTextField ("0",3);
              t3 = new JTextField ("0",3);
              t4 = new JTextField ("0",3);
              t5 = new JTextField ("0",3);
              t1.setEditable( false );
              t2.setEditable( false );
              t3.setEditable( false );
              t4.setEditable( false );
              t5.setEditable( false );
              responsePanel.setLayout(new GridLayout(5,1));
              responsePanel.add(t1);
              responsePanel.add(t2);
              responsePanel.add(t3);
              responsePanel.add(t4);
              responsePanel.add(t5);
              questionPanel.setLayout(new GridLayout(4,1));
              questionPanel.add(label1);
              questionPanel.add(q1);
              questionPanel.add(q2);
              questionPanel.add(q3);
              centerPanel.add(buttonPanel,BorderLayout.CENTER);
              centerPanel.add(responsePanel,BorderLayout.EAST);
              container.add(centerPanel,BorderLayout.WEST);
              container.add(questionPanel,BorderLayout.NORTH);
              q1.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que1[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp1 = String.valueOf(que1[0]);
              t1.setText(temp1);
              else if (e.getSource() == b2)     {
                   que1[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp2 = String.valueOf(que1[1]);
              t2.setText(temp2);
              else if (e.getSource() == b3)     {
                   que1[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp3 = String.valueOf(que1[2]);
              t3.setText(temp3);
              else if (e.getSource() == b4)     {
                   que1[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp4 = String.valueOf(que1[3]);
              t4.setText(temp4);
              else if (e.getSource() == b5)     {
                   que1[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp5 = String.valueOf(que1[4]);
              t5.setText(temp5);
    } //end action performed
              q2.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que2[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp6 = String.valueOf(que2[0]);
              t1.setText(temp1);
              else if (e.getSource() == b2)     {
                   que2[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp7 = String.valueOf(que2[1]);
              t2.setText(temp7);
              else if (e.getSource() == b3)     {
                   que2[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp8 = String.valueOf(que2[2]);
              t3.setText(temp8);
              else if (e.getSource() == b4)     {
                   que2[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp9 = String.valueOf(que2[3]);
              t4.setText(temp9);
              else if (e.getSource() == b5)     {
                   que2[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp10 = String.valueOf(que2[4]);
              t5.setText(temp10);
    } //end action performed
              q3.addActionListener(
                   new ActionListener(){
              public void actionPerformed( ActionEvent e )          
    {                                        //actionPerformed of all registered listeners
              if (e.getSource() == b1) {
                   que3[0] = Integer.parseInt(t1.getText()) + 1;
                   String temp11 = String.valueOf(que3[0]);
              t1.setText(temp11);
              else if (e.getSource() == b2)     {
                   que3[1] = Integer.parseInt(t2.getText()) + 1;
                   String temp12 = String.valueOf(que3[1]);
              t2.setText(temp12);
              else if (e.getSource() == b3)     {
                   que3[2] = Integer.parseInt(t3.getText()) + 1;
                   String temp13 = String.valueOf(que3[2]);
              t3.setText(temp13);
              else if (e.getSource() == b4)     {
                   que3[3] = Integer.parseInt(t4.getText()) + 1;
                   String temp14 = String.valueOf(que3[3]);
              t4.setText(temp14);
              else if (e.getSource() == b5)     {
                   que3[4] = Integer.parseInt(t5.getText()) + 1;
                   String temp15 = String.valueOf(que3[4]);
              t5.setText(temp15);
    } //end action performed
    }//end constructor test
    public void itemStateChanged(ItemEvent item) {
    //int state = item.getStateChange();
    //if (q1 == item.SELECTED)
              public class ButtonPanel extends JPanel
                   public ButtonPanel()
              public class CenterPanel extends JPanel
                   public CenterPanel()
              public class QuestionPanel extends JPanel
                   public QuestionPanel()
              public class ResponsePanel extends JPanel
                   public ResponsePanel()
    public static void main(String [] args)
         test surveyFrame = new test("Student Survey") ;
         surveyFrame.setSize( 500,300 );
         surveyFrame.setVisible(true);
         surveyFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
         }//end main
    }//end class test

    is not abstract and does not override abstract method actionPerformed
    Oh, I see that the title of your post is an error message? Ok. Well, the test class is declared as implementing an ActionListener. That means the test class must have an actionPerformed() method. Your test class apparently does not.
    It does not appear that the test class needs to implement ActionListener. You are using annonymous classes as listeners.

  • Missing method body or declare abstract error

    Hi!
    I have been working on this simple Java 1.3.1 program for three days now and cannot figure out what I am doing wrong. If anyone has done the "Building an Application" tutorial in the New to Java Programming Center, you might recognize the code. I am trying to set up a frame with panels first using the BorderLayout and then the FlowLayout within each section of the BorderLayout. It will have textfields and checkboxes. I am working on the code to retrieve the user input from the text boxes and also to determine which checkbox the user has checked. Here is my code: (ignore my irrelivent comments!)
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import java.awt.event.*;
    import java.awt.Color.*;
    import java.awt.Image.*;
    //Header Comment for a Routine/Method
    //This method gathers the input text supplied by the user from five text fields on the Current
    //Purchase tab of the tabbed pane of the MPGLog.java program. The way it gathers the text
    //depends on the current processing state, which it retrieves on its own. It saves the text to
    //a text file called textinput.txt.
    public class CollectTextInput extends JPanel implements ActionListener
    { // Begin class
         //Declare all the objects needed first.
         // These are the text fields
         private JTextField currentMileage;
         private JTextField numofGallonsBought;
         private JTextField dateofPurchase;
         private JTextField pricePerGallon;
         private JTextField gasBrand;
         // Declaring the Labels to go with each TextField
         private JLabel lblcurrentMileage;
         private JLabel lblnumofGallonsBought;
         private JLabel lbldateofPurchase;
         private JLabel lblpricePerGallon;
         private JLabel lblgasBrand;
         // Declaring the Checkboxes for the types of gas bought
         private JCheckBox chbxReg;
         private JCheckBox chbxSuper;
         private JCheckBox chbxUltra;
         private JCheckBox chbxOther;
         private JCheckBox chbxHigher;
         private JCheckBox chbxLower;
         // Declaring the Buttons and images needed
         private JButton enter;
         private JButton edit;
         //private JButton report; //Will be used later
         private JLabel bluecar;          //Used with the ImageIcon to create CRV image
         private JPanel carimage;     //Used in buildImagePanel method
         private JPanel datum;          //Used in buildDatumPanel method
         private JPanel gasgrade;     //Used in buildGasTypePanel method.
         //Declaring the Panels that need to be built and added
         //to the border layout of this panel.
         //private JPanel panlimages;
         //private JPanel panltextinputs;
         //private JPanel panlchkBoxes;
         // Class to handle functionality of checkboxes
         ItemListener handler = new CheckBoxHandler();
         // This is where you add the constructor for the class - I THINK!!
         public CollectTextInput()
         { // Opens collectTextInput constructor
              // Must set layout for collectTextInput here
              // Choosing a BorderLayout because we simply want to
              // add panels to the North, Center and South borders, which, by
              // default, will fill the layout with the three panels
              // we are creating
              setLayout(new BorderLayout());
              //Initialize the objects in the constructor of the class.
              //Initialize the textfields
              currentMileage = new JTextField();
              numofGallonsBought = new JTextField();
              dateofPurchase = new JTextField();
              pricePerGallon = new JTextField();
              gasBrand = new JTextField();
              // Initialize the labels that go with each TextField
              lblcurrentMileage = new JLabel("Enter the mileage at the time of gas purchase: ");
              lblnumofGallonsBought = new JLabel("Enter the number of gallons of gas bought: ");
              lbldateofPurchase = new JLabel("Enter the date of the purchase: ");
              lblpricePerGallon = new JLabel("Enter the price per gallon you paid for the gas: ");
              lblgasBrand = new JLabel("Enter the brand name of the gas: ");
              //Initialize the labels for the checkboxes.
              chbxReg = new JCheckBox("Regular ", true);
              chbxSuper = new JCheckBox("Super ");
              chbxUltra = new JCheckBox("Ultra ");
              chbxOther = new JCheckBox("Other: (Choose one from below) ");
              chbxHigher = new JCheckBox("Higher than Ultra ");
              chbxLower = new JCheckBox("Lower than Ultra ");
              //Initialize the buttons that go on the panel.
              enter = new JButton("Save Data");
              edit = new JButton("Edit Data");
              //Initialize the image that oges on the panel.
              bluecar = new JLabel("2002 Honda CR-V", new ImageIcon("CRVBlue.jpg"),JLabel.CENTER);
              // Now bring it all together by calling the other methods
              // that build the other panels and menu.
              buildImagePanel();
              buildDatumPanel();
              buildGasTypePanel();
              // Once the methods above build the panels, this call to add
              //  them will add the panels to the main panel's border
              // layout manager.
              add(datum, BorderLayout.NORTH);
              add(carimage, BorderLayout.EAST);
              add(gasgrade, BorderLayout.CENTER);
         } // Ends the constructor.
            // This method creates a panel called images that holds the car image.
         public void buildImagePanel();
         { // Opens buildImagePanel.
              // First, create the Panel
              carimage = new JPanel();
              //Second, set the color and layout.
              carimage.setBackground(Color.white);
              carimage.setLayout(new FlowLayout());
              // Third, add the image to the panel.
              carimage.add(bluecar);
         }// Closes buildImagePanel
         //This method creates a panel called datum that holds the text input.
         public void buildDatumPanel();
         { //Opens buildDatumPanel
              // First, create the Panel.
              datum = new JPanel();
              //Second, set the background color and layout.
              datum.setBackground(Color.white);
              datum.setLayout(new GridLayout(2, 4, 20, 20));
              //Third, add the textfields and text labels to the panel.
              datum.add(lblcurrentMileage);
              datum.add(currentMileage);
              datum.add(lblnumofGallonsBought);
              datum.add(numofGallonsBought);
              datum.add(lbldateofPurchase);
              datum.add(dateofPurchase);
              datum.add(lblpricePerGallon);
              datum.add(pricePerGallon);
              datum.add(lblgasBrand);
              datum.add(gasBrand);
              //Optionally - Fourth -set a border around the panel, including
              // a title.
              datum.setBorder(BorderFactory.createTitledBorder("Per Purchase Information"));
              //Fifth - Add listeners to each text field to be able to
              //  know when data is input into them.
              currentMileage.addActionListener(this);
              numofGallonsBought.addActionListener(this);
              dateofPurchase.addActionListener(this);
              pricePerGallon.addActionListener(this);
              gasBrand.addActionListener(this);
         }// Closes buildDatumPanel
         // This method builds a panel called gasTypePanel that holds the checkboxes.
         public void buildGasTypePanel()
         { // Opens buildGasTypePanel method
              // First, create the panel.
              gasgrade = new JPanel();
              // Second, set its background color and its layout.
              gasgrade.setBackground(Color.white);
              gasgrade.setLayout(new GridLayout(5, 1, 10, 20));
              // Third, add all the checkboxes to the panel.
              gasgrade.add(chbxReg);
              gasgrade.add(chbxSuper);
              gasgrade.add(chbxUltra);
              gasgrade.add(chbxOther);
              gasgrade.add(chbxHigher);
              gasgrade.add(chbxLower);
              //Optionally, - Fourth - set a border around the panel, including
              // a title.
              gasgrade.setBorder(BorderFactory.createTitledBorder("Gas Type Information"));
              // Fifth - CheckBoxes require a CheckBox Handler.
              // This is a method created separately
              // outside of the method where the checkboxes are added to
              // the panel or where the checkboxes are even created.
              // This method (CheckBox Handler) implements and ItemListener
              // and is a self-contained method all on its own. See
              // the CheckBox Handler methods following the
              // actionPerformed method which follows.-SLM
         } // Closes the buildGasTypePanel method
    // Create the functionality to capture and react to an event
    //   for the checkboxes when they are checked by the user and
    //   the text fields to know when text is entered. Also to react to the
    //   Enter button being pushed and the edit button being pushed.
    public void actionPerformed(ActionEvent evt)
    { // Opens actionPerformed method.
         if((evt.getSource() == currentMileage) || (evt.getSource() == enter))
              { // Opens if statement.
                // Retrieves the text from the currentMileage text field
                //  and assigns it to the variable currentMileageText of
                //  type String.
                String currentMileageText = currentMileage.getText();
                lblcurrentMileage.setText("Current Mileage is:    " + currentMileageText);
                // After printing text to JLabel, hide the text field.
                currentMileage.setVisible(false);
           } // Ends if statement.
          if((evt.getSource() == numofGallonsBought) || (evt.getSource() == enter))
              { // Opens if statement.
                // Retrieves the text from the numofGallonsBought text field
                //  and assigns it to the variable numofGallonsBoughtText of
                //  type String.
                String numofGallonsBoughtText = numofGallonsBought.getText();
                lblnumofGallonsBought.setText("The number of gallons of gas bought is:    " + numofGallonsBoughtText);
                // After printing text to JLabel, hide the text field.
                numofGallonsBought.setVisible(false);
           } // Ends if statement.
           if((evt.getSource() == dateofPurchase) || (evt.getSource() == enter))
                     { // Opens if statement.
                       // Retrieves the text from the dateofPurchase text field
                       //  and assigns it to the variable dateofPurchaseText of
                       //  type String.
                       String dateofPurchaseText = dateofPurchase.getText();
                       lbldateofPurchase.setText("The date of this purchase is:    " + dateofPurchaseText);
                       // After printing text to JLabel, hide the text field.
                       dateofPurchase.setVisible(false);
           } // Ends if statement.
           if((evt.getSource() == pricePerGallon) || (evt.getSource() == enter))
                            { // Opens if statement.
                              // Retrieves the text from the pricePerGallon text field
                              //  and assigns it to the variable pricePerGallonText of
                              //  type String.
                              String pricePerGallonText = pricePerGallon.getText();
                              lblpricePerGallon.setText("The price per gallon of gas for this purchase is:    " + pricePerGallonText);
                              // After printing text to JLabel, hide the text field.
                              pricePerGallon.setVisible(false);
           } // Ends if statement.
           if((evt.getSource() == gasBrand) || (evt.getSource() == enter))
                       { // Opens if statement.
                         // Retrieves the text from the gasBrand text field
                         //  and assigns it to the variable gasBrandText of
                         //  type String.
                         String gasBrandText = gasBrand.getText();
                         lblgasBrand.setText("The Brand of gas for this purchase is:    " + gasBrandText);
                         // After printing text to JLabel, hide the text field.
                         gasBrand.setVisible(false);
           } // Ends if statement.
           // This provides control statements for the Edit button. If the
           //  Edit button is clicked, then the text fields are visible again.
           if(evt.getSource() == edit)
           { // Opens if statement.
             // If the edit button is pressed, the following are set to
             //  visible.
                currentMileage.setVisible(true);
                numofGallonsBought.setVisible(true);
                dateofPurchase.setVisible(true);
                pricePerGallon.setVisible(true);
                gasBrand.setVisible(true);
         }// Closes if statement.
    } // Closes actionPerformed method.
         private class CheckBoxHandler implements ItemListener
         { // Opens inner class
              public void itemStateChanged (ItemEvent e)
              {// Opens the itemStateChanged method.
                   JCheckBox source = (JCheckBox) e.getSource();
                        if(e.getStateChange() == ItemEvent.SELECTED)
                             source.setForeground(Color.blue);
                        else
                             source.setForeground(Color.black);
                        }// Closes the itemStateChanged method
                   }// Closes the CheckBoxHandler class.
    } //Ends the public class collectTextInput classThe error I keep receiving is as follows:
    C:\jdk131\CollectTextInput.java:128: missing method body, or declare abstract
         public void buildImagePanel();
    ^
    C:\jdk131\CollectTextInput.java:142: missing method body, or declare abstract
         public void buildDatumPanel();
    ^
    2 errors
    I have looked this error up in three different places but the solutions do not apply to what I am trying to accomplish.
    Any help would be greatly appreciated!! Thanks!
    Susan

    C:\jdk131\CollectTextInput.java:128: missing methodbody, or declare ?abstract
    public void buildImagePanel();^
    C:\jdk131\CollectTextInput.java:142: missing methodbody, or declare abstract
    public void buildDatumPanel();Just remove the semicolons.
    Geesh! If I had a hammer I would be hitting myself over the head with it right now!!! What an obviously DUMB newbie mistake!!!
    Thanks so much for not making me feel stupid! :-)
    Susan

  • Product is not abstract and does not override abstract method

    Received the following errors.
    Product.java:3: Product is not abstract and does not override abstract method ge
    tDisplayText() in Displayable
    public class Product implements Displayable
    ^
    Product.java:16: getDisplayText() in Product cannot implement getDisplayText() i
    n Displayable; attempting to use incompatible return type
    found : void
    required: java.lang.String
    public void getDisplayText()
    ^
    2 errors
    Code reads as follows
    import java.text.NumberFormat;
    public class Product implements Displayable
         private String code;
         private String description;
         private double price;
         public Product()
              this.code = "";
              this.description = "";
              this.price = 0;
    public void getDisplayText()
    String message =
    "Code: " + code + "\n" +
    "Description: " + description + "\n" +
    "Price: " + this.getFormattedPrice() + "\n";
         public Product(String code, String description, double price)
              this.code = code;
              this.description = description;
              this.price = price;
         public void setCode(String code)
              this.code = code;
         public String getCode(){
              return code;
         public void setDescription(String description)
              this.description = description;
         public String getDescription()
              return description;
         public void setPrice(double price)
              this.price = price;
         public double getPrice()
              return price;
         public String getFormattedPrice()
              NumberFormat currency = NumberFormat.getCurrencyInstance();
              return currency.format(price);
    Please help!

    Received the following errors.
    Product.java:3: Product is not abstract and does not
    override abstract method ge
    tDisplayText() in Displayable
    public class Product implements Displayable
    ^
    Product.java:16: getDisplayText() in Product cannot
    implement getDisplayText() i
    n Displayable; attempting to use incompatible return
    type
    found : void
    required: java.lang.String
    public void getDisplayText()
    ^
    2 errors
    Code reads as follows
    Please use the code tags when posting code. There is a code button right above the text box where you enter your post. Click on it and put the code between the code tags.
    These error messages are quite clear in telling what is wrong. You have an Interface called Displayable that specifies a method something like thispublic String getDisplayText() {But in your Product source code, you created thismethodpublic void getDisplayText() {The compiler is complaining because the methods are not the same.
    You also need to return a String in the method probalby like thisreturn message;

Maybe you are looking for