Results 1 to 3 of 3
  1. #1
    patriotsfan is offline Member
    Join Date
    May 2011
    Rep Power

    Default Need help with ActionEvent/ItemEvent

    I am trying to call the displayJButtonActionPerformed(evt) from 8 different JCheckBox methods similar to the one I posted below. I want to do this because it is more efficient and will cut down on some code. I have used this in the past but now that I am using an Actionevent and and ItemEvent I am getting an error when using (evt) as a a parameter, when trying to use displayJButtonActionPerformed(evt) in the addAnotherJCheckBoxItemStateChanged. I am using netbeans GUi editor so it created the methods for me when I select the acton I want to use. The error says....
    Required: java.awt.event.ActionEvent
    Found: java.awt.event.ItemEvent

    What Can I do to fix this?

    private void displayJButtonActionPerformed(java.awt.event.Actio nEvent evt) {
    Invoice showInvoice = new Invoice();

    private void addAnotherJCheckBoxItemStateChanged(java.awt.event .ItemEvent evt) {

    if (addAnotherJCheckBox.isSelected())
    Invoice.isaddOneChecked = true;
    Invoice.isaddOneChecked = false;

    Invoice showInvoice = new Invoice();

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    Refactor. Specifically take the code which you want to be common to displayJButtonActionPerformed() and the various checkbox methods and put it into its own method. Then call that method each time you need it.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

Similar Threads

  1. What does (this) and ActionEvent e mean?
    By africanhacker in forum New To Java
    Replies: 3
    Last Post: 02-06-2011, 06:08 PM
  2. StringBuilder/ActionEvent help!
    By Red727 in forum New To Java
    Replies: 8
    Last Post: 12-07-2010, 04:01 AM
  3. Problems with ActionEvent for JButton
    By TrueBear in forum AWT / Swing
    Replies: 1
    Last Post: 08-24-2009, 04:26 PM
  4. [SOLVED] Actionevent problem
    By Cymro in forum New To Java
    Replies: 3
    Last Post: 04-04-2008, 07:11 AM
  5. ActionEvent example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 12:00 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