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

    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();
    showInvoice.calculate();
    }

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

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

    Invoice showInvoice = new Invoice();
    showInvoice.calculate();
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

Similar Threads

  1. What does (this) and ActionEvent e mean?
    By africanhacker in forum New To Java
    Replies: 3
    Last Post: 02-06-2011, 05:08 PM
  2. StringBuilder/ActionEvent help!
    By Red727 in forum New To Java
    Replies: 8
    Last Post: 12-07-2010, 03: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-11-2008, 11:00 PM

Posting Permissions

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