Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 3rd, 2006, 02:51 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 13
ActionListener + ItemListener ?

i have a JComboBox along with buttons.addActionListener.

i have the action listener attatched to two buttons already and i am trying to attatch an item listener to my JComboBox, is this possible when i already have an action listner ?.. when i try to implement them both it gives me a missing open curly bracket bug '{'
Code:
class Payroll extends JPanel implements ActionListener implements ItemListener
{
......

}


would i be able to implement both in the class ?
or can i attatch the JComboBox with the actionlistener and just code it in the Actionperformed method ?

Code:
JComboBox cb = new JComboBox();
cb.addActionListener();

public void ActionPerformed(ActionEven evt)
{

         
        if (evt.getSource() == compute)
        {    
            hours_worked = ((Number)hourField.getValue()).intValue();
            payRate = ((Number)payfield.getValue()).doubleValue();
            dependants = ((Number)depField.getValue()).intValue();
            
            double grossPay = computeGross(payRate, hours_worked, over_time);
            GrossField.setValue(new Double(grossPay));
            
            double fed = computeFed(grossPay,fedRate);
            fedField.setValue(new Double(fed));
            
            double heal = computeHealth(grossPay, dependants);
            healthField.setValue(new Double(heal));
            
            double fc = computeFica(grossPay, max_tax);
            ficaField.setValue(new Double(fc));
            
            double nf = computeNetPay(grossPay, fed, heal, fc);
            netField.setValue(new Double(nf));
        }
        else if(evt.getSource() == clear)
        {
            nameField.setValue(" ");
            hourField.setValue(0);
            payfield.setValue(0);
            depField.setValue(0);
            GrossField.setValue(0);
            fedField.setValue(0);
            healthField.setValue(0);
            ficaField.setValue(0);
            netField.setValue(0);
        }
        else if(evt.getSource() == NoPanel)
        {
            dependants = 0;
            depField.setEditable(false);
        }    
    }



}



my question is can i use cb.addActionListener(this);
and write an if statement inside there that recognizes the JComboBox status change ? or do i need another event method ?

Reply With Quote
  #2  
Old October 3rd, 2006, 05:21 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 14
try:
java Code:
Original - java Code
  1. class Payroll extends JPanel implements ActionListener, ItemListener

Reply With Quote
  #3  
Old October 3rd, 2006, 08:56 PM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 12
Also try removing the last bracket on this code. Looks like you have an extra one.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > ActionListener + ItemListener ?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap