Results 1 to 6 of 6

Thread: GUI problem

  1. #1
    mrarefi is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default GUI problem

    Dear friends

    I have a problem with the wrote program in the Ditel book. I have written the code in eClipse but I have red underline under the name of class "CheckBoxHandler"

    I have copied the program below:

    Java Code:
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.event.ItemListener;
    import java.awt.event.ItemEvent;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.JCheckBox;
    
    public class CheckBoxFrame extends JFrame
    {
        private JTextField textFiled;
        private JCheckBox boldJCheckBox;
        private JCheckBox italicJCheckBox;
        
        public CheckBoxFrame()
        {
            super("text bold & italic");
            setLayout(new FlowLayout());
            
            textFiled = new JTextField("watch the font style change",20);
            textFiled.setFont(new Font("Serif", Font.PLAIN, 14));
            add(textFiled);
            
            boldJCheckBox = new JCheckBox("Bold");
            italicJCheckBox = new JCheckBox("Italic");
            add(boldJCheckBox);
            add(italicJCheckBox);
            
            CheckBoxHandler handeler = new CheckBoxHandler();
            boldJCheckBox.addItemListener(handeler);
            italicJCheckBox.addItemListener(handeler);
        }
        
         private class CheckBoxHandler implements ItemListener
        {
            public void ItemStateChange(ItemEvent event)
            {
                Font font = null;
                
                if (boldJCheckBox.isSelected() && italicJCheckBox.isSelected())
                    font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
                
                else if (boldJCheckBox.isSelected())
                    font = new Font("Serif", Font.BOLD,14);
                
                else if (italicJCheckBox.isSelected())
                    font = new Font("Serif",Font.ITALIC, 14);
                
                else font = new Font("Serif",Font.PLAIN,14);
                
                textFiled.setFont(font);
                
            }
    
            
    
                
        }
    }
    [COLOR=#333333][/COLOR]


    and this is the main class:

    Java Code:
    import javax.swing.JFrame;
    
    
    public class mainClass   {
        
        public static void main(String[] args )
        {
            CheckBoxFrame chechBoxFrame = new CheckBoxFrame();
            chechBoxFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            chechBoxFrame.setSize(275,100);
            chechBoxFrame.setVisible(true);
            
        }
    
    }
    [COLOR=#333333][/COLOR]
    Last edited by mrarefi; 11-17-2013 at 08:09 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: GUI problem

    What is the full text of the compiler's error message?


    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: GUI problem

    Can you copy and paste here the compiler's error messages?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    mrarefi is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: GUI problem

    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
    The type CheckBoxFrame.CheckBoxHandler must implement the inherited abstract method ItemListener.itemStateChanged(ItemEvent)

    at CheckBoxFrame$CheckBoxHandler.itemStateChanged(Che ckBoxFrame.java:34)
    at javax.swing.AbstractButton.fireItemStateChanged(Un known Source)
    at javax.swing.AbstractButton$Handler.itemStateChange d(Unknown Source)
    at javax.swing.DefaultButtonModel.fireItemStateChange d(Unknown Source)
    at javax.swing.JToggleButton$ToggleButtonModel.setSel ected(Unknown Source)
    at javax.swing.JToggleButton$ToggleButtonModel.setPre ssed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
    The type CheckBoxFrame.CheckBoxHandler must implement the inherited abstract method ItemListener.itemStateChanged(ItemEvent)

    at CheckBoxFrame$CheckBoxHandler.itemStateChanged(Che ckBoxFrame.java:34)
    at javax.swing.AbstractButton.fireItemStateChanged(Un known Source)
    at javax.swing.AbstractButton$Handler.itemStateChange d(Unknown Source)
    at javax.swing.DefaultButtonModel.fireItemStateChange d(Unknown Source)
    at javax.swing.JToggleButton$ToggleButtonModel.setSel ected(Unknown Source)
    at javax.swing.JToggleButton$ToggleButtonModel.setPre ssed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,814
    Rep Power
    25

    Default Re: GUI problem

    CheckBoxFrame.CheckBoxHandler must implement the inherited abstract method ItemListener.itemStateChanged(ItemEvent)
    The error message is telling you that the CheckBoxHandler class must implement the itemStateChanged() method.

    Check that you have spelled it correctly.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    mrarefi is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Problem with a Simple Histogram Problem
    By kathmandu in forum New To Java
    Replies: 12
    Last Post: 06-25-2013, 02:19 AM
  2. Replies: 0
    Last Post: 11-07-2012, 01:44 PM
  3. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 04:43 AM
  4. Replies: 9
    Last Post: 09-21-2010, 05:15 PM
  5. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 07:12 AM

Posting Permissions

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