Click here to Skip to main content
14,207,068 members
   

Java

 
PinnedForum Guidelines - PLEASE READ Pin
Chris Maunder28-Jul-09 2:36
adminChris Maunder28-Jul-09 2:36 
QuestionBasic Calculator Write a program that works as a simple calculator. 1.It reads a character (ch) 2.If ch is among '+', '-', '*', '/' or '%' it furthur takes two numbers (N1 and N2 as input). It then performs appropriate appropriate operation between n Pin
Member 1450000613-Jun-19 22:55
memberMember 1450000613-Jun-19 22:55 
AnswerRe: Basic Calculator Write a program that works as a simple calculator. 1.It reads a character (ch) 2.If ch is among '+', '-', '*', '/' or '%' it furthur takes two numbers (N1 and N2 as input). It then performs appropriate appropriate operation betwe Pin
Richard Deeming14-Jun-19 0:55
mveRichard Deeming14-Jun-19 0:55 
AnswerRe: Basic Calculator Write a program that works as a simple calculator. 1.It reads a character (ch) 2.If ch is among '+', '-', '*', '/' or '%' it furthur takes two numbers (N1 and N2 as input). It then performs appropriate appropriate operation betwe Pin
Richard MacCutchan14-Jun-19 1:06
protectorRichard MacCutchan14-Jun-19 1:06 
QuestionMessage Closed Pin
23-May-19 21:02
memberMember 1438028323-May-19 21:02 
QuestionFailed to grab focus on a Jtextfield Pin
Member 1413007922-May-19 4:06
memberMember 1413007922-May-19 4:06 
SuggestionRe: Failed to grab focus on a Jtextfield Pin
Richard MacCutchan22-May-19 21:32
protectorRichard MacCutchan22-May-19 21:32 
GeneralRe: Failed to grab focus on a Jtextfield Pin
Member 1413007923-May-19 1:07
memberMember 1413007923-May-19 1:07 
GeneralRe: Failed to grab focus on a Jtextfield Pin
Richard MacCutchan23-May-19 1:44
protectorRichard MacCutchan23-May-19 1:44 
Questioncloudsim algorithm Genitic Pin
Member 1423906220-May-19 8:20
memberMember 1423906220-May-19 8:20 
AnswerRe: cloudsim algorithm Genitic Pin
Richard MacCutchan20-May-19 22:09
protectorRichard MacCutchan20-May-19 22:09 
QuestionHow can i make Jtexfield updates when Jtable values are changed? Pin
Member 141300798-May-19 2:36
memberMember 141300798-May-19 2:36 
Hey guys i have a Jtable shown as : IdP | NameProduct | Quantity | Price |Stock

i have created this method :
public  int calculatesum(){
        int total=0; 
             for(int i=0;i<table.getRowCount();i++){
                 
                  
            
                   int  amount = Integer.parseInt((String)table.getValueAt(i, 2).toString());
                   int amprice = Integer.parseInt((String)table.getValueAt(i, 3).toString());
                   total=total+(amount*amprice);
                     
            
            }
             
             return total;
             
    }


that calculates multipilication of (Price*Quantity) and put result in a Jtexfield and called this method in a button action:
private void buttonsearchActionPerformed(java.awt.event.ActionEvent evt) {                                             

        conn = DatabaseConnection.dbConnection();
        try {
                    String Sql="select idp,nomp,prix,stock from produit where codep='" + textsearch.getText() + "'";
                    pst = conn.prepareStatement(Sql);


            ResultSet rs = pst.executeQuery();
            
            Object[] columns = {"Id Produit", "Nom Produit", "Quantité", "Prix", "Stock"};
        
            Object[] row = new Object[5];
            if (rs.next()){
            row[0] = rs.getInt("idp");
            row[1] = rs.getString("nomp");
            row[2] = 1;
            row[3] = rs.getString("prix");
            row[4] = rs.getString("stock");
           
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            model.addRow(row);}
            //table.repaint();
            
            calculatesum();
            pricetext.setText(Integer.toString(calculatesum()));

          
             
            

        } catch (Exception e) {

            JOptionPane.showMessageDialog(null, e);

        }
        


                    

    }             


My problem is: any changes on quantity won't update the Jtextfield automatically until the button is pressed again. so How can i make the Jtextfield (aka result) changes on the time i change quantity
thanks for help
AnswerRe: How can i make Jtexfield updates when Jtable values are changed? Pin
Richard MacCutchan8-May-19 2:48
protectorRichard MacCutchan8-May-19 2:48 
GeneralRe: How can i make Jtexfield updates when Jtable values are changed? Pin
Member 141300798-May-19 3:02
memberMember 141300798-May-19 3:02 
GeneralRe: How can i make Jtexfield updates when Jtable values are changed? Pin
Richard MacCutchan8-May-19 3:19
protectorRichard MacCutchan8-May-19 3:19 
Questionprogramation cloudsim java Pin
Member 142390627-May-19 0:06
memberMember 142390627-May-19 0:06 
AnswerRe: programation cloudsim java Pin
Eddy Vluggen7-May-19 0:32
mveEddy Vluggen7-May-19 0:32 
GeneralRe: programation cloudsim java Pin
jschell18-May-19 7:01
memberjschell18-May-19 7:01 
QuestionRe: programation cloudsim java Pin
Eddy Vluggen18-May-19 8:29
mveEddy Vluggen18-May-19 8:29 
AnswerRe: programation cloudsim java Pin
Richard MacCutchan18-May-19 20:56
protectorRichard MacCutchan18-May-19 20:56 
GeneralRe: programation cloudsim java Pin
Eddy Vluggen18-May-19 22:42
mveEddy Vluggen18-May-19 22:42 
GeneralRe: programation cloudsim java Pin
Richard MacCutchan19-May-19 1:05
protectorRichard MacCutchan19-May-19 1:05 
GeneralRe: programation cloudsim java Pin
Eddy Vluggen19-May-19 1:19
mveEddy Vluggen19-May-19 1:19 
GeneralRe: programation cloudsim java Pin
Richard MacCutchan19-May-19 1:45
protectorRichard MacCutchan19-May-19 1:45 
GeneralRe: programation cloudsim java Pin
Eddy Vluggen19-May-19 8:58
mveEddy Vluggen19-May-19 8:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190612.1 | Last Updated 14 Jun 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid