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: jtable calculation issue

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jtable calculation issue

    my problem is i want to calculated the multiplication and addition of all the entries into sin gal value and that value i need to stored in database in front of its rows then total no of rows value is calculated into total data type. but i do not want to stored total of cost of customer that i need to print on page.. so just help me and help me out from these problem please.. `



    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.*;
    import java.util.Vector;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    public class TestTable
    {
    public static void main(String[] args)
    {
    TestTable testTable = new TestTable();
    }
    public TestTable()
    {
    EventQueue.invokeLater(new Runnable()
    {
    @Override
    public void run()
    {
    try
    {
    UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
    }
    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setLayout(new BorderLayout());
    frame.add(new TestTable.Bill());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    }
    });
    }
    public class Bill extends JPanel implements ActionListener
    {
    JTextField textFieldId;
    JLabel l1;
    JLabel l2;
    JButton b1,b2,b3;
    JTextField sun,sunr,sat,satr,oth,othr,totall;
    int[] a = new int[16];
    int i=0;
    ResultSet rs1 = null;
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    private int rows;
    public Bill()
    {
    setLayout(new BorderLayout());
    JPanel fields = new JPanel();
    textFieldId = new JTextField(10);
    l1 = new JLabel("New Customer Entry );
    l2 = new JLabel("Customer Id");
    b1 = new JButton("OK");
    b2 = new JButton("Calculate");
    b3 = new JButton("Print");
    fields.add(l2);
    fields.add(textFieldId);
    fields.add(b1);
    fields.add(b2);
    fields.add(b3);
    add(fields, BorderLayout.NORTH);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    // Don't forget to add a table.
    add(new JScrollPane(new JTable(model)));
    }
    @Override
    public void actionPerformed(ActionEvent e)
    {
    System.out.println("You clicked the button");
    if (e.getSource() == b1)
    {
    PreparedStatement ps = null;
    try
    {
    Connection con;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbcdbc:devendra");
    ps = con.prepareStatement("SELECT * FROM Customer where Customer_Id = ?");
    // You must bind the parameter with a value...
    ps.setString(1, textFieldId.getText());
    rs1 = ps.executeQuery();
    model.addColumn("Customer_Id");
    model.addColumn("Customer_Name");
    model.addColumn("Contact");
    model.addColumn("Paper_Name");
    model.addColumn("Sunday");
    model.addColumn("Rate");
    model.addColumn("Satarday");
    model.addColumn("Rate");
    model.addColumn("Other Day");
    model.addColumn("Rate");
    while (rs1.next())
    {
    model.addRow(new Object[]{rs1.getString(1),rs1.getString(2),rs1.getString(3 ),rs1.getString(4),rs1.getString(5),
    rs1.getString(6),rs1.getString(7),rs1.getString(8) ,rs1.getString(9),rs1.getString(10),rs1.getString( 11)});
    }
    Vector data = model.getDataVector();

    JOptionPane.showMessageDialog(null, "You successfully Enter the Entry");
    }
    catch (SQLException s)
    {
    System.out.println("SQL code does not execute.");
    JOptionPane.showMessageDialog(null, "Please Enter the Detail Correctly");
    } catch (Exception exp)
    {
    JOptionPane.showMessageDialog(this, "Failed to perform query: " + exp.getMessage());
    } finally
    {
    try {
    ps.close();
    }
    catch (Exception ex)
    {
    }
    }
    }
    if (e.getSource() == b2)
    {

    }
    }
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,610
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: jtable calculation issue

    When posting code, please use the highlight tags to preserve formatting.

    Also, I honestly have no idea what you're asking here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: jtable calculation issue

    i think i have lots of problem
    let me ask in sequentially...
    if u run the program u will get the customer id text box with three button which are ok,calculate and print button.
    when u enter the customer id and pressed ok then in tabular format u get all the detail of that customer with their news paper name
    and in each news paper row u will find separate column like Sunday,rate,Saturday,rate,other day ,rate column.ok
    do u get uphill these....

Similar Threads

  1. BMI calculation
    By dantheman in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 28th, 2012, 10:57 PM
  2. simulate calculation ?
    By meryqat in forum Java Theory & Questions
    Replies: 3
    Last Post: April 30th, 2012, 02:03 PM
  3. JTable selection issue
    By kpat in forum AWT / Java Swing
    Replies: 2
    Last Post: April 1st, 2012, 02:38 PM
  4. I need calculation
    By Swiss518 in forum Loops & Control Statements
    Replies: 7
    Last Post: January 27th, 2011, 01:26 PM
  5. RPM Calculation
    By fobos3 in forum Algorithms & Recursion
    Replies: 2
    Last Post: September 21st, 2010, 09:53 AM

Tags for this Thread