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 3 of 3

Thread: newbie in programming i need help

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default newbie in programming i need help

    i need help guys about this program sales using import
    import java.awt.*;
    import javax.wing.*;
    import java.awt.event.*;
    that have JFrame, label, combo box, button..here is an example but i need a new one..
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class Sales extends JFrame implements ActionListener,ItemListener{
    	double totalPrice = 0.00;
    	int i=0;
    	JLabel lblProduct = new JLabel("Product Name :");
    	JLabel lblCart = new JLabel("Cart            :");
    	JLabel lblPrice = new JLabel("Price :");
    	String productList[] = {"Cake","Ice Cream", "Chocolate", "Sprite","Coke"};
    	double priceList[] = {100,200,300,400,500};
    	JButton btnAdd = new JButton("Add");
    	JButton btnCancel = new JButton("Cancel");
    	JButton btnRemove = new JButton("Remove");
    	JComboBox cmbProduct= new JComboBox(productList);
    	JComboBox cmbCart = new JComboBox();
    	JTextField txtPrice = new JTextField(20);
    	public Sales(){
    		cmbProduct.addItemListener(this);
    		btnCancel.addActionListener(this);
    		btnAdd.addActionListener(this);
    		btnRemove.addActionListener(this);
     
    		JPanel panel1 = new JPanel(new GridLayout(3,3));
    		panel1.add(lblProduct);
    		panel1.add(cmbProduct);
    		panel1.add(lblPrice);
    		panel1.add(txtPrice);
    		panel1.add(btnAdd);
    		panel1.add(btnCancel);
     
    		JPanel panel2 = new JPanel(new GridLayout(1,2));
    		panel2.add(lblCart);
    		panel2.add(cmbCart);
     
    		JPanel panel3 = new JPanel(new BorderLayout());
    		panel3.add(panel2,BorderLayout.PAGE_START);
    		panel3.add(btnRemove,BorderLayout.PAGE_END);
     
     
     
    		JPanel mainPanel = new JPanel(new BorderLayout());
    		mainPanel.add(panel1, BorderLayout.PAGE_START);
    		mainPanel.add(panel3,BorderLayout.PAGE_END);
     
    		setContentPane(mainPanel);
    		setSize(300,160);
    		setVisible(true);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	}
    	public void itemStateChanged(ItemEvent e){
    		Object o = e.getSource();
    		if(o==cmbProduct){
    			i = cmbProduct.getSelectedIndex();
    			if(i==0){
    				txtPrice.setText(Double.toString(priceList[i]));
    			}else if(i==1){
    				txtPrice.setText(Double.toString(priceList[i]));
    			}else if(i==2){
    				txtPrice.setText(Double.toString(priceList[i]));
    			}else if(i==3){
    				txtPrice.setText(Double.toString(priceList[i]));
    			}else if(i==4){
    				txtPrice.setText(Double.toString(priceList[i]));
    			}else{
    				txtPrice.setText("");
    			}
    		}	
    	}
    	public void actionPerformed(ActionEvent e){
    		Object o = e.getSource();
    		if(o==btnAdd){
    			cmbCart.addItem(cmbProduct.getSelectedItem());
    //			totalPrice += Double.parseDouble(txtPrice.getText());
    		}else if(o==btnRemove){
    			cmbCart.removeItem(cmbCart.getSelectedItem());
    		}
    		else if(o==btnCancel){
    			txtPrice.setText(null);
    			cmbProduct.setSelectedItem(null);
    		}
    //		JOptionPane.showMessageDialog(null,Double.toString(totalPrice));
    	}
    	public static void main(String[] args){
    		Sales s = new Sales();
    	}
    }
    Last edited by helloworld922; October 6th, 2011 at 12:53 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: newbie in programming i need help

    A) Please wrap your code in the code tags ([highlight=java]Your code here[/highlight]). B) Perhaps someone will come along that understands what you are asking, but I have no idea what your question is...please rephrase your question, and be precise and concise - it helps you to help us answer your question with information and a defined question.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: newbie in programming i need help

    thanks for replying my thread sir sir i need a new code..like in the cashier sir, product and their price and their vat..that have jframe, jlabel, jcombobox, jbutton... like this sir Image - TinyPic - Free Image Hosting, Photo Sharing & Video Hosting

Similar Threads

  1. programming newbie
    By blue02gls in forum Member Introductions
    Replies: 6
    Last Post: October 7th, 2011, 11:32 AM
  2. Java and programming newbie needing help
    By speedmaster in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 8th, 2010, 07:57 AM
  3. Newbie to any type of Programming
    By kcljeremy in forum Java Theory & Questions
    Replies: 5
    Last Post: September 10th, 2010, 07:27 AM
  4. Help to a newbie!
    By painthygrave in forum AWT / Java Swing
    Replies: 0
    Last Post: April 7th, 2010, 10:29 PM
  5. Newbie Programming problem
    By Pingu in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 02:10 AM