3 Replies - 984 Views - Last Post: 03 April 2013 - 06:49 PM Rate Topic: -----

#1 Sonia Kaushik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-April 13

sum of results using adaptor class across frame

Posted 03 April 2013 - 01:14 AM

 import java.awt.*;


import java.sql.*;


import java.awt.event.*;

import javax.swing.*;

public class clothes extends JFrame implements ActionListener {
    JFrame frame= new JFrame();
	JPanel panel1= new JPanel();
	JLabel price= new JLabel("Price");
	JLabel quantity= new JLabel("Quantity");
	JLabel total= new JLabel("Total");
	JLabel shirt = new JLabel("Shirt");
	JTextField p1= new JTextField(10);
	JTextField q1= new JTextField(10);
	JTextField t1= new JTextField(10);

	JLabel tshirt = new JLabel("T-Shirt");
	JTextField p2= new JTextField(10);
	JTextField q2= new JTextField(10);
	JTextField t2= new JTextField(10);
	JLabel trouser = new JLabel("Trouser");
	JTextField p3= new JTextField(10);
	JTextField q3= new JTextField(10);
	JTextField t3= new JTextField(10);
	JLabel jeans = new JLabel("Jeans");
	JTextField p4= new JTextField(10);
	JTextField q4= new JTextField(10);
	JTextField t4= new JTextField(10);
	
	JPanel panel2= new JPanel();
	JLabel price1= new JLabel("Price");
	JLabel quantity1= new JLabel("Quantity");
	JLabel total1= new JLabel("Total");
	JLabel lshirt = new JLabel("Shirt");
	JTextField p5= new JTextField(10);
	JTextField q5= new JTextField(10);
	JTextField t5= new JTextField(10);

	JLabel ltshirt = new JLabel("T-Shirt");
	JTextField p6= new JTextField(10);
	JTextField q6= new JTextField(10);
	JTextField t6= new JTextField(10);
	JLabel suits = new JLabel("Suits");
	JTextField p7= new JTextField(10);
	JTextField q7= new JTextField(10);
	JTextField t7= new JTextField(10);
	JLabel ljeans = new JLabel("Jeans");
	JTextField p8= new JTextField(10);
	JTextField q8= new JTextField(10);
	JTextField t8= new JTextField(10);
	JButton confirm= new JButton("Confirm");

	JButton bill= new JButton("Bill");
	JButton bill1= new JButton("Bill");
    GridBagLayout grid = new GridBagLayout();
	GridBagConstraints con = new GridBagConstraints();
	FlowLayout flow= new FlowLayout();
	public void init()
	{
		DBUtil db = new DBUtil();
		//frame.setLayout(null);
		setLayout(flow);
		panel1.setBounds(0,0,200,200);
		panel1.setBorder(BorderFactory.createTitledBorder("Boys"));
		panel2.setBounds(201,20,200,200);
		panel2.setBorder(BorderFactory.createTitledBorder("Girls"));
		add(panel1);
		add(panel2);
		panel1.setLayout(grid);
		panel2.setLayout(grid);
		con.insets= new Insets(5,5,5,5);
		con.gridx=0;
		con.gridy=1;
		panel1.add(shirt,con);

		con.gridx=1;
		con.gridy=0;
		panel1.add(price,con);
		con.gridx=1;
		con.gridy=1;
		panel1.add(p1,con);
		
		con.gridx=3;
		con.gridy=0;
		panel1.add(quantity,con);
		con.gridx=3;
		con.gridy=1;
		panel1.add(q1,con);
		con.gridx=5;
		con.gridy=0;
		panel1.add(total,con);
		con.gridx=5;
		con.gridy=1;
		panel1.add(t1,con);
		
		con.gridx=0;
		con.gridy=2;
		panel1.add(tshirt,con);

		con.gridx=1;
		con.gridy=2;
		panel1.add(p2,con);
		
		con.gridx=3;
		con.gridy=2;
		panel1.add(q2,con);
		
		con.gridx=5;
		con.gridy=2;
		panel1.add(t2,con);
		
		con.gridx=0;
		con.gridy=3;
		panel1.add(trouser,con);

		con.gridx=1;
		con.gridy=3;
		panel1.add(p3,con);
		
		con.gridx=3;
		con.gridy=3;
		panel1.add(q3,con);
		
		con.gridx=5;
		con.gridy=3;
		panel1.add(t3,con);

		con.gridx=0;
		con.gridy=4;
		panel1.add(jeans,con);

		con.gridx=1;
		con.gridy=4;
		panel1.add(p4,con);
		
		con.gridx=3;
		con.gridy=4;
		panel1.add(q4,con);
		
		con.gridx=5;
		con.gridy=4;
		panel1.add(t4,con);


		con.gridx=0;
		con.gridy=1;
		panel2.add(lshirt,con);

		con.gridx=1;
		con.gridy=0;
		panel2.add(price1,con);
		con.gridx=1;
		con.gridy=1;
		panel2.add(p5,con);
		
		con.gridx=3;
		con.gridy=0;
		panel2.add(quantity1,con);
		con.gridx=3;
		con.gridy=1;
		panel2.add(q5,con);
		con.gridx=5;
		con.gridy=0;
		panel2.add(total1,con);
		con.gridx=5;
		con.gridy=1;
		panel2.add(t5,con);
		
		con.gridx=0;
		con.gridy=2;
		panel2.add(ltshirt,con);

		con.gridx=1;
		con.gridy=2;
		panel2.add(p6,con);
		
		con.gridx=3;
		con.gridy=2;
		panel2.add(q6,con);
		
		con.gridx=5;
		con.gridy=2;
		panel2.add(t6,con);
		
		con.gridx=0;
		con.gridy=3;
		panel2.add(suits,con);

		con.gridx=1;
		con.gridy=3;
		panel2.add(p7,con);
		
		con.gridx=3;
		con.gridy=3;
		panel2.add(q7,con);
		
		con.gridx=5;
		con.gridy=3;
		panel2.add(t7,con);

		con.gridx=0;
		con.gridy=4;
		panel2.add(ljeans,con);

		con.gridx=1;
		con.gridy=4;
		panel2.add(p8,con);
		
		con.gridx=3;
		con.gridy=4;
		panel2.add(q8,con);
		
		con.gridx=5;
		con.gridy=4;
		panel2.add(t8,con);
		
		con.gridx=9;
		con.gridy=15;
		panel1.add(confirm,con);
		
		con.gridx=10;
		con.gridy=15;
		panel1.add(bill,con);
		con.gridx=10;
		con.gridy=15;
		panel2.add(bill1,con);

		p1.addActionListener(this);
		q1.addActionListener(this);
		t1.addActionListener(this);
		p2.addActionListener(this);
		q2.addActionListener(this);
		t2.addActionListener(this);
		p3.addActionListener(this);
		q3.addActionListener(this);
		t3.addActionListener(this);
		p4.addActionListener(this);
		q4.addActionListener(this);
		t4.addActionListener(this);
		p5.addActionListener(this);
		q5.addActionListener(this);
		t5.addActionListener(this);
		p6.addActionListener(this);
		q6.addActionListener(this);
		t6.addActionListener(this);
		p7.addActionListener(this);
		q7.addActionListener(this);
		t7.addActionListener(this);
		p8.addActionListener(this);
		q8.addActionListener(this);
		t8.addActionListener(this);
		bill.addActionListener(this);
		bill1.addActionListener(this);
		
		t1.setEditable(false);
		t2.setEditable(false);
		t3.setEditable(false);
		t4.setEditable(false);
		t5.setEditable(false);
		t6.setEditable(false);
		t7.setEditable(false);
		t8.setEditable(false);

//frame.setBackground(Color.pink);
panel1.setBackground(Color.pink);
panel2.setBackground(Color.orange);
		setVisible(true);
		//setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(525,475);
	//pack();
	}
	
	
	
	
public static void main(String args[])
{
	clothes cloth= new clothes();
	cloth.init();
}




@Override
public void actionPerformed(ActionEvent e) {
	// TODO Auto-generated method stub
	
	if(e.getSource()==q1)
	{
	int x,y,z;
	x =Integer.parseInt(p1.getText());
	y=Integer.parseInt(q1.getText());
	z=x*y;
	t1.setText(String.valueOf(z));
	}
	if(e.getSource()==q2)
	{
	int x,y,z;
	x =Integer.parseInt(p2.getText());
	y=Integer.parseInt(q2.getText());
	z=x*y;
	t2.setText(String.valueOf(z));
	}
	if(e.getSource()==q3)
	{
	int x,y,z;
	x =Integer.parseInt(p3.getText());
	y=Integer.parseInt(q3.getText());
	z=x*y;
	t3.setText(String.valueOf(z));
	}
	if(e.getSource()==q4)
	{
	int x,y,z;
	x =Integer.parseInt(p4.getText());
	y=Integer.parseInt(q4.getText());
	z=x*y;
	t4.setText(String.valueOf(z));
	}
	if(e.getSource()==q5)
	{
	int x,y,z;
	x =Integer.parseInt(p5.getText());
	y=Integer.parseInt(q5.getText());
	z=x*y;
	t5.setText(String.valueOf(z));
	}
	if(e.getSource()==q6)
	{
	int x,y,z;
	x =Integer.parseInt(p6.getText());
	y=Integer.parseInt(q6.getText());
	z=x*y;
	t6.setText(String.valueOf(z));
	}
	if(e.getSource()==q7)
	{
	int x,y,z;
	x =Integer.parseInt(p7.getText());
	y=Integer.parseInt(q7.getText());
	z=x*y;
	t7.setText(String.valueOf(z));
	}
	if(e.getSource()==q8)
	{
	int x,y,z;
	x =Integer.parseInt(p8.getText());
	y=Integer.parseInt(q8.getText());
	z=x*y;
	t8.setText(String.valueOf(z));
	}

	if(e.getSource()=="thankspage")
	{
		thankspage tp= new thankspage();
		tp.init();
	}
	}
}




Is This A Good Question/Topic? 0
  • +

Replies To: sum of results using adaptor class across frame

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: sum of results using adaptor class across frame

Posted 03 April 2013 - 03:29 AM

Please give us more info: What's wrong? What questions do you have? The thread title isn't enough, and, in this case, isn't even understandable. If you have errors, post them.

Your code is typical of that generated by a drag and drop GUI constructor. Some of those are great tools and can provide useful results in minimum time, but the code you posted is an example of the difficulties present when one accepts the output of those tools without modification. For example:

- Zero comments. What the heck does this thing do?
- Lousy variable names. Worse than lousy. Those that believe in the concept of the "self-documenting program" (I don't) base it on choosing variable and method names that explain their purpose. Quite the opposite concept in the code you posted.

I could go on, but I won't.

Please provide more info (with better code, if possible), or good luck, and have a nice day.
Was This Post Helpful? 0
  • +
  • -

#3 Sonia Kaushik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-April 13

Re: sum of results using adaptor class across frame

Posted 03 April 2013 - 05:20 AM

[code]
thanks for response.
when you run this code then window open with one frame or two panels i.e one for boys and second for girls. I want to get total from boys panel when click on bill and same for girls panel using adapter class or another way if u can tell me.
Have a great day
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: sum of results using adaptor class across frame

Posted 03 April 2013 - 06:49 PM

Don't want to be rude but learn to use arrays before writting sunch an horror
Would curt the number of your lines of code by 10
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1