Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: New line in TextArea(clicking on radiobutton)

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy New line in TextArea(clicking on radiobutton)

    This is the output:
    Untitled.jpg
    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.
    Untitled1.jpg

    WHat i wanted to happen is that it'll tally my selections. Like this:
    ((I ONLY EDITED THIS))
    12.jpg

    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;
     
    	Main(){
    		getContentPane();
     
    		setSize(550,490);
    		setVisible(true);
    		setLayout(null);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setTitle("Tricia's Grocery Store");
     
    		add(lblTitle=new JLabel("Tricia's Grocery Store"));
    		lblTitle.setFont(new Font("Broadway", Font.PLAIN, 35));
    		lblTitle.setBounds(50,0,600,80);
     
    		add(radApple=new JRadioButton("Apples ---------- P15.75"));
    		add(radOrange=new JRadioButton("Oranges -------- P12.50"));
    		add(radPomelo=new JRadioButton("Pomelos -------- P95.25"));
     
    		radApple.setBounds(70,100,150,50);
    		radOrange.setBounds(70,130,155,50);
    		radPomelo.setBounds(70,160,155,50);
     
    		bg = new ButtonGroup();
    		bg.add(radApple);
    		bg.add(radOrange);
    		bg.add(radPomelo);
     
    		add(lblQty=new JLabel("Quantity:"));
    		lblQty.setBounds(70,200,150,50);
     
    		add(txtQty=new JTextField(2));
    		txtQty.setBounds(150,210,70,30);
     
    		add(lblTotal=new JLabel("P0.00"));
    		lblTotal.setBounds(150,500,500,500);
     
    		add(btnAdd=new Button("Add Item"));
    		btnAdd.setBounds(70,270,80,20);
     
    		add(btnPrint=new Button("Print Receipt"));
    		btnPrint.setBounds(150,270,80,20);
     
    		add(btnCancel=new Button("Reset Values"));
    		btnCancel.setBounds(70,290,80,20);
     
    		add(btnExit=new Button("Close"));
    		btnExit.setBounds(150,290,80,20);
     
    		add(txtScreen=new JTextArea());
    		txtScreen.setFont(new Font("Courier",Font.PLAIN,15));
    		txtScreen.setBounds(250,100,270,320);
    		//txtScreen.setEditable(false);
     
     
    		btnAdd.addActionListener(this);	
    		radApple.addActionListener(this);
    		radOrange.addActionListener(this);
    		radPomelo.addActionListener(this);
    		txtQty.addActionListener(this);
    	}
     
    	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);
    			txtQty.setText(null);
    		}
    		if (radOrange.isSelected()){
    			orangeprice += 12.50 * qty;
    			strOranges = ("Oranges ------  x" + txtQty.getText()+ " ----- P" + orangeprice);
    			txtScreen.setText(strApples + strOranges + strPomelos);
    			txtQty.setText(null);
     
    		}
    		if (radPomelo.isSelected()){
    			pomeloprice += 95.25 * qty;
    			strPomelos = ("Pomelos ------  x" + txtQty.getText()+ " ----- P" + pomeloprice);
    			txtScreen.setText(strApples + strOranges + strPomelos);
    			txtQty.setText(null);
    		}
     
    	}
    }
    Attached Images Attached Images
    Last edited by curmudgeon; March 3rd, 2013 at 11:48 AM. Reason: annoying bold text removed


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: New line in TextArea(clicking on radiobutton)

    Please avoid shouting in the forum.

    If you are serious need of quick help, consider replying to Norm who tried to help you in your previous question on this site which you have abandoned. Many here will avoid helping folks who abandon threads as we feel that they are likely to abandon and ignore this one, so why put in the effort to help?

Similar Threads

  1. How to clear the textArea?
    By dynamix24 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 25th, 2013, 08:46 AM
  2. [SOLVED] Help! ComboBox, CheckBox, RadioButton and TextArea/TextField
    By Kinshen09 in forum AWT / Java Swing
    Replies: 6
    Last Post: November 17th, 2012, 07:32 PM
  3. How to use a TreeView with a RadioButton
    By williamdasflores in forum AWT / Java Swing
    Replies: 3
    Last Post: December 1st, 2011, 10:07 AM
  4. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  5. Storing radiobutton into file
    By aretium in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 31st, 2011, 10:21 AM