Results 1 to 2 of 2
  1. #1
    D.Calladine is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default Using another form

    Hi, My problem is i have a button that brings up a form. the user then enters two piece of information into this form a barcode and a price what i want is when i click ok of the new from the data is sent to the old form and a method is ran. my only problem is if i put the method right after creating an instant of the new form and makign it visible the method just runs. i only want it to run right after i have clicked the ok button on the new form. here are some snippits of code

    Java Code:
    private void discountBtActionPerformed(java.awt.event.ActionEvent evt) {                                           
            discountItems discount = new discountItems();
            addItem(discount.getBarcode(), discount.getPrice());
    and here is the other form

    Java Code:
    private void okBtActionPerformed(java.awt.event.ActionEvent evt) {                                     
            if (barcodeTf.getText().length() < 10) {
                JOptionPane.showMessageDialog(rootPane, "Please Enter 10 Digit Barcode");
            } else if (discountPriceTf.getText().length() == 0) {
                JOptionPane.showMessageDialog(rootPane, "Please Enter a Discount Price");
            } else {
                discountPrice = Double.parseDouble(discountPriceTf.getText());
                barcode = barcodeTf.getText();
    Any help you be very well appricated Thank you

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Using another form

    Either you want to be using a JDialog of some sort, or you want to give the second (form) thing a callback method.
    So user clicks button on FormA.
    FormA creates FormB, supplying itself as a callabck (I'd make it an interface, since that'll make it easier to change if need be). That callback interface will simply have an updateDiscount(barcode, price) method.
    FormB will call that method on the stored callback, inside that okBtACtionPErformed method above.

    Personally I'd go for the JDialog.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 6
    Last Post: 04-06-2011, 01:39 PM
  2. Replies: 8
    Last Post: 10-03-2010, 10:45 AM
  3. Replies: 1
    Last Post: 03-22-2010, 10:03 AM
  4. Replies: 0
    Last Post: 10-31-2009, 10:24 AM
  5. Replies: 10
    Last Post: 08-12-2009, 05:02 PM

Tags for this Thread

Posting Permissions

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