English 中文(简体)
通知和通过物体
原标题:ActionPerformed and passing an object
  • 时间:2011-11-02 09:46:16
  •  标签:
  • java

......

public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == saleButton)
        {
            processSale(Wine wi);
            //System.out.println("fvghj");
        }
        else if (e.getSource() == returnButton)
        {
                processReturn(Wine wi);
            //System.out.println("fdgchj"); 
        }

    }


    //create a wine object to be returned - responsible for getting details from textfields when either sale or return is pressed
    //this object is then passed to the relevant method in LWMGUI to process either sale or return


public Wine getWine()
    {
        String wName = nameWineText.getText();

        String costBottles = costBottleText.getText();
        int cBottle = Integer.parseInt(costBottles);
        //System.out.println(cBottle);

        //get numBottle
        String numBottles = numBottlesText.getText();
        int nBottle = Integer.parseInt(numBottles);
        //System.out.println(nBottle);

        Wine wi = new Wine(wName, cBottle, nBottle);

        return wi;

    }


    private int processSale(Wine wi)
    {
        int totalSaleAmount = wi.getNumBottle() * (int) wi.getCostBottle();
        //System.out.println(totalAmount);
        transactionText.setText("" + totalSaleAmount);
        return totalSaleAmount;
    }

    private int processReturn(Wine wi)
    {
        int totalReturnAmount = wi.getNumBottle() * (int) wi.getCostBottle();
        //System.out.println(totalReturnAmount);
        transactionText.setText("" + totalReturnAmount);
        return totalReturnAmount;
    }

......I m having problems with an actionPerformed method. I have got text from user input textfields to give me the cost, quantity and name of a wine, for a sale or return to be processed. I have created a Wine object (wi) with this information, and want to pass it to further methods, whether sale or return.

I can t get the processSale() or processReturn() methods to work, and I m really confused!! I thought passing the Wine wi object to the methods would work? Here is the relevant code;

问题回答

说明

processSale(getWine())

processReturn(getWine())

实际上,你在发出新的酒吧时都没有任何东西。 因此,您的这两种方法总是有 null的 null。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签