0

I am using JFrame for my program Photo of program. When you enter value of a quantity in the text field and selects another item from the Jlist, the value stays and doesn't empty the text field. So what i want to happen is emptying the text field when I am about to choose another item from the list.

Here is the code for that portion:

if (selected == "SBCA Jacket"){
        photo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jacket.jpg")));
        double p = 700;
        String price = Double.toString(p);
        priceField.setText(price);
        int s = 500;
        String stock = Integer.toString(s);
        stockField.setText(stock);
        int qty = Integer.parseInt(qtyField.getText());
        int rstock = s - qty;  
        rstockField.setText(Integer.toString(rstock));
        double total = p * qty;
        totalField.setText(Double.toString(total));

    }else if (selected == "SBCA T-shirt"){
    ...
  • Would be nice if we dont habe to guess how your JFrame looks like. [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Jérôme Mar 12 '17 at 09:35
  • What the looks of things, you're storing `String`s in a `JList`, but there is a bunch of other information about each item which should also be stored with it (like it's price), so, instead of using a `String`, you should have some object which encapsulates all the relevant information and putting those into the `JList`, it will make your life SO much simpler – MadProgrammer Mar 12 '17 at 10:01

0 Answers0