This is the output:
This happens when I input "1" in the quantity textfield.
(The quantity textfield turns null after inputing a value)

But when I put "1" in the quantity textfield and click Oranges, it overwrites the Apples.

WHat i wanted to happen is that it'll tally my selections. Like this:

These are my codes so far:

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class Main extends JFrame implements ActionListener{

    JLabel lblTitle, lblQty, lblTotal;
    JRadioButton radApple, radOrange, radPomelo;
    JTextField txtQty;
    JTextArea txtScreen;
    Button btnAdd, btnPrint, btnCancel, btnExit, btnStock;

    ButtonGroup bg;


        setTitle("Tricia's Grocery Store");

        add(lblTitle=new JLabel("Tricia's Grocery Store"));
        lblTitle.setFont(new Font("Broadway", Font.PLAIN, 35));

        add(radApple=new JRadioButton("Apples ---------- P15.75"));
        add(radOrange=new JRadioButton("Oranges -------- P12.50"));
        add(radPomelo=new JRadioButton("Pomelos -------- P95.25"));


        bg = new ButtonGroup();

        add(lblQty=new JLabel("Quantity:"));

        add(txtQty=new JTextField(2));

        add(lblTotal=new JLabel("P0.00"));

        add(btnAdd=new Button("Add Item"));

        add(btnPrint=new Button("Print Receipt"));

        add(btnCancel=new Button("Reset Values"));

        add(btnExit=new Button("Close"));

        add(txtScreen=new JTextArea());
        txtScreen.setFont(new Font("Courier",Font.PLAIN,15));


    public static void main(String[]args){
        Main main = new Main();

    public void actionPerformed(ActionEvent e) {
        double appleprice=0, orangeprice=0, pomeloprice=0;
        int qty = Integer.parseInt(txtQty.getText());
        String strApples= "", strOranges = "", strPomelos = "";

        if (radApple.isSelected()){
            appleprice += 15.75 * qty;
            strApples = ("Apples ------  x" + txtQty.getText()+ " ----- P" + appleprice);
            txtScreen.setText(strApples + strOranges + strPomelos);
        if (radOrange.isSelected()){
            orangeprice += 12.50 * qty;
            strOranges = ("Oranges ------  x" + txtQty.getText()+ " ----- P" + orangeprice);
            txtScreen.setText(strApples + strOranges + strPomelos);

        if (radPomelo.isSelected()){
            pomeloprice += 95.25 * qty;
            strPomelos = ("Pomelos ------  x" + txtQty.getText()+ " ----- P" + pomeloprice);
            txtScreen.setText(strApples + strOranges + strPomelos);


that's because you use setText instead of append

commented: Compensating for inappropriate downvote +0

Instead of setText, use append to append your new text to the text that's already in the text area. (You may want a new line character "\n" as well)

commented: Doesn't deserve downvote +14
commented: Doesn't deserve to be downvoted, the given answer is correct. +13

Instead of

 txtScreen.setText(strApples + strOranges + strPomelos); //line 103

Try this:-

 txtScreen.setText(txtScreen.getText + "\n" +strOranges);



Similarly at other places

commented: Agreed with Sanjay on this one, no evidence that IIM would have seen the earlier posts and his answer has helped the OP without obvious spoonfeeding IMO +11
commented: Not really spoonfeeding IMO plus the answer was posted at around the same time as other answers +14
commented: Duplicates info in previous posts. Spoon-feeds answer rather than helping learning. -3



@iciaguevara:- mark thread as solved if your problem is solved.

@james:- Please explain why downvoted.I just explained this how to do.Moreover,i was typing code and then posted.I like to code and then give solution rather than just giving solution without proof.I haven;t down voted your thread that you thought it was me who down voted.It might be the author of this post who down voted,not me.

OK. No I didn't assume you downvoted - all votes without a comment are anonymous by design. There's no connection between the votes on my/stultuske's posts, and the downvote on yours.
In this forum we try to avoid giving people code they can copy/paste without understanding. Your post didn't explain how to do it. It just says "copy this code and your homework will be OK" - no attempt to explain why. If it hadn't already got an upvote I may not have voted, but under the circumstances I didn't think I could let an upvote stand unchallenged.
The earlier posts were examples of giving the OP enough info to do a little research and solve the problem for themselves. Follow that example and you will see more upvotes.

It's not about some damm points.I am not here to earn points or something.But it is about helping others to understand.

that's because you use setText instead of append

Instead of setText, use append to append your new text to the text that's already in the text area. (You may want a new line character "\n" as well)

This is just a spoof of above line.After that my statement just tell how to do a line change.I am not copying entire code and making them just copy-paste my code.It is just a line in which i am pointing out error.First understand the difference between showing code and showing error-line code.

Stultiuske and I posted simultaneously, that's quite a common event. Maybe your post was also simultaneous, but that's irrelevant to the teach vs spoonfeed point. You don't have to agree with me; there are many other active members in this forum who will vote as they see fit. I'm now going to have dinner....

It is aready explained in Stultiuske i just helped what exactly is the root cause.
Before judging others post check the one,this posted by you.That is an example of spoonfeeding.You are just printing complete code.I just gave a line reference.

If it hadn't already got an upvote I may not have voted, but under the circumstances I didn't think I could let an upvote stand unchallenged.

@James:- the above two link i gave were from the one that were upvoted and you were doing spoon feeding.Should i do the same thing?
There is a line between showing entire coding nad showing error line and how to change it.Understand the difference than judge.

Folks, let's not turn this thread into a warzone. I'll close the thread by saying this:

IMO no one in this thread is copying other solutions or posting ready-to-use entire solutions; neither James nor IIM. I can't control personal opinions (manifested via means of up/down-votes) but let's just admit that all of us, at some point in time have either posted short one-line answers or full code snippets to help out the OP. Let's not forget the real reason of why we actually spend our free time on this forum; to help out people without causing problems for others. I don't think anyone in this thread is guilty of anything. To offset random downvoting, I have upvoted the posts accordingly.

If someone wants to take this further, I would be more than happy to discuss things via PM.