newbie in programming i need help
i need help guys about this program sales using import
Code Java:
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..
Code Java:
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();
}
}
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.
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