...Can anybody knows how can I put a table on what type of Package type (overnight and two day package) in my program..

Since I have been troubled on how I would like to display my added data to an array and if I have choose a certain package type then later if I would like to display that type of package the data being addded is being displayed in an sorted way...

Here are my current program....

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

public class PACKAGE extends JFrame implements ActionListener
{

   String trackingno="";
   String name="";
   String address="";
   String city="";
   String state="";
   int zipcode=0;
   String packagetype="";
   double weight=0.0;
   double Ounce=0.0;
   double others=0.0;
   double payment=0.0;

   private OverNightPackage p1;

   String[] PackageItem={"Choose Package","Over Night Package","Two Day Package"};
   String[] DisplayItem={"Choose Package","Over Night Package","Two Day Package"};
   public OverNightPackage[] overnightpackage = new OverNightPackage[10];
   public int ctr=0;

   JPanel mainPanel=new JPanel();
   JPanel controlPanel=new JPanel();

   JLabel lblTrackingNo=new JLabel("Tracking No.",SwingConstants.LEFT);
   JLabel lblName=new JLabel("Name",SwingConstants.LEFT);
   JLabel lblAddress=new JLabel("Address",SwingConstants.LEFT);
   JLabel lblCity=new JLabel("City",SwingConstants.LEFT);
   JLabel lblState=new JLabel("State",SwingConstants.LEFT);
   JLabel lblZipCode=new JLabel("Zip Code",SwingConstants.LEFT);
   JLabel lblPackageType=new JLabel("Package Type",SwingConstants.LEFT);
   JLabel lblWeight=new JLabel("Weight",SwingConstants.LEFT);
   JLabel lblOunce=new JLabel("Per Ounce",SwingConstants.LEFT);
   JLabel lblOthers=new JLabel("Others",SwingConstants.LEFT);
   JLabel lblPayment=new JLabel("Payments",SwingConstants.LEFT);

   JTextField txtTrackingNo=new JTextField(20);
   JTextField txtName=new JTextField(20);
   JTextField txtAddress=new JTextField(20);
   JTextField txtCity=new JTextField(20);
   JTextField txtState=new JTextField(20);
   JTextField txtZipCode=new JTextField(20);
   JComboBox cboPackageType=new JComboBox(PackageItem);
   JTextField txtWeight=new JTextField(20);
   JTextField txtOunce=new JTextField(20);
   JTextField txtOthers=new JTextField(20);
   JTextField txtPayment=new JTextField(20);


   JButton btnCompute=new JButton("Compute");
   JButton btnAdd=new JButton("Add");
   JButton btnClear=new JButton("Clear");
   JButton btnExit=new JButton("Exit");
   JButton btnDisplay=new JButton("Display");
   JComboBox cboDisplay=new JComboBox(DisplayItem);

   public PACKAGE()
   {



     super("Compute Per Package");
     setSize(600,600);
     setLocationRelativeTo(null);
     setDefaultCloseOperation(EXIT_ON_CLOSE);
     setLayout(new BorderLayout());

	p1 = new OverNightPackage();

     mainPanel.setLayout(new GridLayout(13,2));
     mainPanel.add(lblTrackingNo);
     mainPanel.add(txtTrackingNo);
     mainPanel.add(lblName);
     mainPanel.add(txtName);
     mainPanel.add(lblAddress);
     mainPanel.add(txtAddress);
     mainPanel.add(lblCity);
     mainPanel.add(txtCity);
     mainPanel.add(lblState);
     mainPanel.add(txtState);
     mainPanel.add(lblZipCode);
     mainPanel.add(txtZipCode);
     mainPanel.add(lblPackageType);
     mainPanel.add(cboPackageType);
     mainPanel.add(lblWeight);
     mainPanel.add(txtWeight);
     mainPanel.add(lblOunce);
     mainPanel.add(txtOunce);
     mainPanel.add(lblOthers);
     mainPanel.add(txtOthers);
     mainPanel.add(lblPayment);
     mainPanel.add(txtPayment);
     add(mainPanel,BorderLayout.WEST);

     controlPanel.setLayout(new GridLayout(6,1));
     controlPanel.add(btnCompute);
     controlPanel.add(btnAdd);
     controlPanel.add(btnClear);
     controlPanel.add(btnExit);
     controlPanel.add(btnDisplay);
     controlPanel.add(cboDisplay);
     add(controlPanel,BorderLayout.EAST);

     btnCompute.addActionListener(this);
     btnAdd.addActionListener(this);
     btnClear.addActionListener(this);
     btnExit.addActionListener(this);
     btnDisplay.addActionListener(this);
     setVisible(true);

     }

     public void actionPerformed(ActionEvent e)
     {

       if(e.getSource()==btnCompute)
       {
		   	p1.setWeight(Double.parseDouble(txtWeight.getText()));
			p1.setOunce(Double.parseDouble(txtOunce.getText()));
			String str_others = txtOthers.getText();
			double others = Double.parseDouble(str_others);
			String text = Double.toString(p1.calculateCost() + others);
			txtPayment.setText(text);
       }

       if(e.getSource()==btnAdd)
       {
          trackingno=txtTrackingNo.getText();
          name=txtName.getText();
          address=txtAddress.getText();
          city=txtCity.getText();
          state=txtState.getText();
          zipcode=Integer.parseInt(txtZipCode.getText());
          packagetype=(String)cboPackageType.getSelectedItem();
          weight=Double.parseDouble(txtWeight.getText());
          Ounce=Double.parseDouble(txtOunce.getText());
          others=Double.parseDouble(txtOthers.getText());
          payment=Double.parseDouble(txtPayment.getText());


            overnightpackage[ctr] = new OverNightPackage(name,address,city,zipcode,state,weight,Ounce,others,payment,trackingno);
            ctr++;
         }



     if(e.getSource()==btnClear)
     {
              txtTrackingNo.setText("");
              txtName.setText("");
              txtAddress.setText("");
              txtCity.setText("");
              txtState.setText("");
              txtZipCode.setText("");
              txtWeight.setText("");
              txtOunce.setText("");
              txtOthers.setText("");
              txtPayment.setText("");
              txtTrackingNo.grabFocus();

     }

     if(e.getSource()==btnExit)
     {
      System.exit(0);
     }

     if(e.getSource()==btnDisplay)
     {
       PersonTable pt=new PersonTable();
     }

     }


   private class PersonTable extends JFrame
   {

      JTable table;
      Object[][]data;
      String[]header={"Tracking No.","Name","Address","City","State","Zip Code","Weight","Ounce","Others","Payments"};
      JScrollPane sp;

      public PersonTable()
      {
        setSize(600,600);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(HIDE_ON_CLOSE);
        data=new Object[overnightpackage.length][header.length];

        for(int i=0;i<ctr;i++)
        {
          data[i][0]=overnightpackage[i].getTrackingNo();
          data[i][1]=overnightpackage[i].getName();
          data[i][2]=overnightpackage[i].getAddress();
          data[i][3]=overnightpackage[i].getCity();
          data[i][4]=overnightpackage[i].getState();
          data[i][5]=overnightpackage[i].getZipCode();
          data[i][6]=overnightpackage[i].getWeight();
          data[i][7]=overnightpackage[i].getOunce();
          data[i][8]=overnightpackage[i].getOthers();
          data[i][9]=overnightpackage[i].getPayment();
        }

      table=new JTable(data,header);
      sp=new JScrollPane(table);

      add(sp);
      setVisible(true);
      }
    }

  public static void main(String[]args)
  {
     PACKAGE pg=new PACKAGE();
  }

}

I have been reading your thread for some time now, searched the google, asked my colleagues, called some of my old professors but still no one can answer this important question:

...Can anybody knows how can I put a table on what type of Package type (overnight and two day package) in my program..

Since I have been troubled on how I would like to display my added data to an array and if I have choose a certain package type then later if I would like to display that type of package the data being addded is being displayed in an sorted way...

What do you mean by that???? It makes no sense! Explain your program and what it does and what you want it to do

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.