java java java

reset and add button

Page 1 of 1

11 Replies - 2311 Views - Last Post: 05 October 2008 - 10:07 AM Rate Topic: -----

#1 smile_myglitz08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 31-July 08

java java java

Post icon  Posted 05 October 2008 - 06:58 AM

package PizzaOrderForm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PizzaOrderForm extends JFrame implements ActionListener{
	
		int totalAmount,orderChange;
	   
	   JPanel mainPanel;
	   JPanel top1Panel,top2Panel,topPanel;
	   JPanel centerPanel,center1Panel,center2Panel,center3Panel;
	   JPanel lowerPanel,northPanel,cntrPanel,southPanel,north1,north2,south1,south2,south3;
	   JCheckBox[] pizzaCrust,pizzaTopping;
	   JRadioButton[] pizzaSize,pizzaDiscount;
	   JLabel quantity,box,top,size,ify,rt,amnt1,amnt2,sum,crust,discount,amntChnge;
	   JComboBox num1;
	   JTextField rate, toAmnt,tenAmnt,change;
	   JTextArea summary;
	   JButton reset,add;
	   JScrollPane scroll;
	   
	   String[] num={"1","2","3","4","5","6","7","8","9","10","11","12"};
	   String[] pizsize = {"Small","Medium","Large","Family size"};
	   String[] piztop = {"Sausage","Pepperoni","Cheese","Hamburger","Olives","Mushrooms","PineApples"};
	   String[] pizcrust= {"Hand-tossed","Thin-crust","Deep dish"};
	   String[] pizdis = {"Yes","No"};
	   
	   public void createPizzaForm(){
	   
		  setTitle("PIZZA ORDER FORM");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setResizable(false);	
		setLocationRelativeTo(null);
				
		
		mainPanel = new JPanel(new BorderLayout());
		top1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		top2Panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		topPanel = new JPanel(new BorderLayout());
		centerPanel = new JPanel(new BorderLayout());
		center1Panel= new JPanel(new GridLayout(4,2));
		center2Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		center3Panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		north1 = new JPanel(new FlowLayout(FlowLayout.CENTER) );
		north2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		northPanel = new JPanel(new BorderLayout());
		cntrPanel = new JPanel(new BorderLayout());
	   	southPanel = new JPanel(new BorderLayout());
		lowerPanel = new JPanel(new BorderLayout());
		
		quantity = new JLabel("QUANTITY: ");
		num1 = new JComboBox(num);
		num1.setSelectedIndex(0);
		box= new JLabel("Box(es)");
		
		top1Panel.add(quantity);
		top1Panel.add(num1);
		top1Panel.add(box);
		
		size =new JLabel("SIZES: ");
		top2Panel.add(size);
		top = new JLabel("TOPPINGS: ");
			
		ButtonGroup groupSize = new ButtonGroup();
		pizzaSize = new JRadioButton[pizsize.length];
		for(int x=0;x<pizsize.length;x++){
			pizzaSize[x]= new JRadioButton(pizsize[x]);
			groupSize.add(pizzaSize[x]);
			top2Panel.add(pizzaSize[x]);
		}
		
		pizzaTopping = new JCheckBox[piztop.length];
		for(int x=0;x<piztop.length;x++){
			center1Panel.add(new JLabel(piztop[x]));
			pizzaTopping[x] = new JCheckBox();
			center1Panel.add(pizzaTopping[x]);
		}
		crust= new JLabel("CRUST:  ");
		center2Panel.add(crust);
		pizzaCrust = new JCheckBox[pizcrust.length];
		for(int x=0;x<pizcrust.length;x++){
			center2Panel.add(new JLabel(piztop[x]));
			pizzaCrust[x] = new JCheckBox();
			center2Panel.add(pizzaCrust[x]);
		}
		discount= new JLabel("Discount? ");
		center3Panel.add(discount);
		ButtonGroup groupDiscount = new ButtonGroup();
		pizzaDiscount = new JRadioButton[pizdis.length];
		for(int x=0;x<pizdis.length;x++){
			pizzaDiscount[x]= new JRadioButton(pizdis[x]);
			groupDiscount.add(pizzaDiscount[x]);
			center3Panel.add(pizzaDiscount[x]);
		}
		
		ify= new JLabel("If yes, ");
		rate= new JTextField(5);
		rt= new JLabel("%");
		north1.add(ify);
		north1.add(rate);
		north1.add(rt);
		reset= new JButton("RESET"); reset.setBackground(Color.red);
		add= new JButton("ADD"); add.setBackground(Color.red);
		north2.add(reset);
		north2.add(add);
		sum= new JLabel("QTY  /  SIZE  /  CRUST  /  PRICE  /  SUBTOTAL");	  
		summary = new JTextArea(5,30);		
		summary.setLineWrap(true);		
		summary.setWrapStyleWord(true);
		scroll = new JScrollPane(summary);
		scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		getContentPane().add(scroll);
	   
		amnt1 = new JLabel("Total Amount");
		amnt2 = new JLabel("Tendered Amount");
		amntChnge = new JLabel("Change");
		toAmnt= new JTextField(10);
		tenAmnt= new JTextField(10);
		change= new JTextField(10);
		
	   	south1 =new JPanel(new FlowLayout(FlowLayout.RIGHT));
	   	south2 = new JPanel (new FlowLayout(FlowLayout.RIGHT));
	   	south3 = new JPanel (new FlowLayout(FlowLayout.RIGHT));
		cntrPanel.add(sum,BorderLayout.NORTH);
		  cntrPanel.add(summary,BorderLayout.CENTER);
		  cntrPanel.add(scroll,BorderLayout.EAST);
		  south1.add(amnt1);
		  south1.add(toAmnt);
		  south2.add(amnt2);
		  south2.add(tenAmnt);
		  south3.add(amntChnge);
		  south3.add(change);   	
		
		
		
		topPanel.add(top1Panel,BorderLayout.NORTH);
		topPanel.add(top2Panel,BorderLayout.CENTER);
		topPanel.add(top,BorderLayout.SOUTH);
		centerPanel.add(center3Panel,BorderLayout.SOUTH);
		centerPanel.add(center2Panel,BorderLayout.CENTER);
		centerPanel.add(center1Panel,BorderLayout.NORTH);
		northPanel.add(north1,BorderLayout.NORTH);
		northPanel.add(north2,BorderLayout.EAST);
		southPanel.add(south1,BorderLayout.NORTH);
		southPanel.add(south2,BorderLayout.CENTER);
		southPanel.add(south3,BorderLayout.SOUTH);
		lowerPanel.add(northPanel,BorderLayout.NORTH);
		lowerPanel.add(cntrPanel,BorderLayout.CENTER);
		  lowerPanel.add(southPanel,BorderLayout.SOUTH);
			
		mainPanel.add(topPanel,BorderLayout.NORTH);
		mainPanel.add(centerPanel,BorderLayout.CENTER);
		mainPanel.add(lowerPanel,BorderLayout.SOUTH);
		
		num1.addActinonListener(this);
		reset.addActionListener(this);
		add.addActionListener(this);
		
	 	add(mainPanel);
		pack();
		setVisible(true);
		   
	   
	
	}
	
	public void actionPerformed(ActionEvent e) {
		Object cbox = e.getSource();
		
		if(cbox==reset){
			
		}
		else if(cbox==add){
			
		}
		
		
			   
	}
	
	 public static void main(String args[]){
		PizzaOrderForm pizza = new PizzaOrderForm();
		pizza.createPizzaForm();
		
	}
	
	
}

/**System.out.println("Order button has been pressed");  
		   for(int i = 0; i < toppings.length; i++)  
			   System.out.println(toppingList[i] + " is " + toppings[i].isSelected());  
		   System.out.println("Quantity is " + (quantity.getSelectedIndex() + 1));  
		   if(ch==add){
				i++;
				text.setText(Integer.toString(i));
				if(i>=10){
					JOptionPane.showMessageDialog(this,"Reach maximum value of 10.");
					}
				}*/


hi.. can you help me.. am still confuse on what kind of implementation i should use for the reset and add button..
hope you could help me..tnx..

Is This A Good Question/Topic? 0
  • +

Replies To: java java java

#2 the_freedom   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-September 08

Re: java java java

Posted 05 October 2008 - 07:29 AM

Hello,
I didn't understand well what you want to do with the "add" button, however, the reset button is pretty simple.
This button is supposed to erase everything that was typed on the program, maybe you should do this:
 rate.setText("");

for all the text fields and areas that you are working with.

If you tell me what you want to do with your "add" button I may help you a little bit more.

=]
Was This Post Helpful? 0
  • +
  • -

#3 smile_myglitz08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 31-July 08

Re: java java java

Posted 05 October 2008 - 07:33 AM

View Postthe_freedom, on 5 Oct, 2008 - 07:29 AM, said:

Hello,
I didn't understand well what you want to do with the "add" button, however, the reset button is pretty simple.
This button is supposed to erase everything that was typed on the program, maybe you should do this:
 rate.setText("");

for all the text fields and areas that you are working with.

If you tell me what you want to do with your "add" button I may help you a little bit more.

=]


with the add button..you can add or select again another order and will be listed on the text area.
And with the reset area..it will reset all..the buttons, checkbox,textarea,textfield will be empty.
can you help me?
Was This Post Helpful? 0
  • +
  • -

#4 the_freedom   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-September 08

Re: java java java

Posted 05 October 2008 - 07:43 AM

Hmmm
You should not use a text area for listing that,
try using a JTable.
It's more organized and can be easely cleaned.
Was This Post Helpful? 0
  • +
  • -

#5 smile_myglitz08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 31-July 08

Re: java java java

Posted 05 October 2008 - 08:03 AM

View Postthe_freedom, on 5 Oct, 2008 - 07:43 AM, said:

Hmmm
You should not use a text area for listing that,
try using a JTable.
It's more organized and can be easely cleaned.



ahh..
ok I'll try the JTable..but how about my Reset and add button??can u gave me some idea
Was This Post Helpful? 0
  • +
  • -

#6 the_freedom   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-September 08

Re: java java java

Posted 05 October 2008 - 08:22 AM

Ok, I'll try.
Well, if you use a JTable when clicking on the "add" Button you should add a line on the tabel with the order details.
String dados[] = {"" + cond.getCod(), "" + cond.getNome(), "" + cond.getUnidadesResidenciais(), "" + cond.getEndereco()};
			modelo.addRow(dados);
			table.setModel(modelo);


A little like that.
The reset button, if it's only to erase the data on the screen you should erase the fields, and with radio buttons and check boxes you should use
jCheckBox1.setSelected(false);


If I were in your shoes i would add a "Erase" button that would clean the selected table line
Was This Post Helpful? 0
  • +
  • -

#7 smile_myglitz08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 31-July 08

Re: java java java

Posted 05 October 2008 - 09:00 AM

View Postthe_freedom, on 5 Oct, 2008 - 08:22 AM, said:

Ok, I'll try.
Well, if you use a JTable when clicking on the "add" Button you should add a line on the tabel with the order details.
String dados[] = {"" + cond.getCod(), "" + cond.getNome(), "" + cond.getUnidadesResidenciais(), "" + cond.getEndereco()};
			modelo.addRow(dados);
			table.setModel(modelo);


A little like that.
The reset button, if it's only to erase the data on the screen you should erase the fields, and with radio buttons and check boxes you should use
jCheckBox1.setSelected(false);


If I were in your shoes i would add a "Erase" button that would clean the selected table line



with the add button., am confused with the terms u used..and should i put it in my actionPerformed method?? am i right?? tnx.
Was This Post Helpful? 0
  • +
  • -

#8 the_freedom   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-September 08

Re: java java java

Posted 05 October 2008 - 09:14 AM

String titulo[] = {"Column1", "Column2", "Column4", "Column4"};
	DefaultTableModel modelo = new DefaultTableModel(titulo, 0) {
		public boolean isCellEditable(int row, int col) {
			return false;
		}


Use this to create the table and set it's columns.
Then to fill the table you should use this:

String dados[] = {"Column1Value", "Column2Value", "Column3Value", "Column4Value"};
			modelo.addRow(dados);//Adding the row with the values to the table
			table.setModel(modelo);//Putting these rows on the table, like a refresh


Better now?
Was This Post Helpful? 0
  • +
  • -

#9 smile_myglitz08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 31-July 08

Re: java java java

Posted 05 October 2008 - 09:22 AM

View Postthe_freedom, on 5 Oct, 2008 - 09:14 AM, said:

String titulo[] = {"Column1", "Column2", "Column4", "Column4"};
	DefaultTableModel modelo = new DefaultTableModel(titulo, 0) {
		public boolean isCellEditable(int row, int col) {
			return false;
		}


Use this to create the table and set it's columns.
Then to fill the table you should use this:

String dados[] = {"Column1Value", "Column2Value", "Column3Value", "Column4Value"};
			modelo.addRow(dados);//Adding the row with the values to the table
			table.setModel(modelo);//Putting these rows on the table, like a refresh


Better now?



yah! better..i'll try to check it out..
thanks for the ideas..
Was This Post Helpful? 0
  • +
  • -

#10 smile_myglitz08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 31-July 08

Re: java java java

Posted 05 October 2008 - 09:31 AM

View Postthe_freedom, on 5 Oct, 2008 - 09:14 AM, said:

String titulo[] = {"Column1", "Column2", "Column4", "Column4"};
	DefaultTableModel modelo = new DefaultTableModel(titulo, 0) {
		public boolean isCellEditable(int row, int col) {
			return false;
		}


Use this to create the table and set it's columns.
Then to fill the table you should use this:

String dados[] = {"Column1Value", "Column2Value", "Column3Value", "Column4Value"};
			modelo.addRow(dados);//Adding the row with the values to the table
			table.setModel(modelo);//Putting these rows on the table, like a refresh


Better now?



WOULD YOU MIND IF I ASK WHERE SHOULD I PUT ALL THOSE CODES IN MY CODE?? AM STILL CONFUSED..AM REALLY SORRY.. AM STILL A BEGINNER IN JAVA..
Was This Post Helpful? 0
  • +
  • -

#11 the_freedom   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-September 08

Re: java java java

Posted 05 October 2008 - 09:44 AM

I'm not used to deal with hand made code, sorry.
I use to draw my screens with NetBeans Designer...
=/

Try using it it's pretty simple

EDIT: Wait a little, with how many pizza orders are you gonna deal?

This post has been edited by the_freedom: 05 October 2008 - 09:47 AM

Was This Post Helpful? 0
  • +
  • -

#12 smile_myglitz08   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 31-July 08

Re: java java java

Posted 05 October 2008 - 10:07 AM

View Postthe_freedom, on 5 Oct, 2008 - 09:44 AM, said:

I'm not used to deal with hand made code, sorry.
I use to draw my screens with NetBeans Designer...
=/

Try using it it's pretty simple

EDIT: Wait a little, with how many pizza orders are you gonna deal?



well, there is no limitations given to us by our prof as long as the client still want to order he/she can still order. unless you will click the reset button. and in the computation the price and total amount and subtotal will automaticaly compute and also the change. every size has its corresponding price and every topping has an additional price.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1