Click here to Skip to main content
15,885,546 members
Home / Discussions / Java
   

Java

 
QuestionFailed to grab focus on a Jtextfield Pin
User 1409759122-May-19 4:06
User 1409759122-May-19 4:06 
SuggestionRe: Failed to grab focus on a Jtextfield Pin
Richard MacCutchan22-May-19 21:32
mveRichard MacCutchan22-May-19 21:32 
GeneralRe: Failed to grab focus on a Jtextfield Pin
User 1409759123-May-19 1:07
User 1409759123-May-19 1:07 
GeneralRe: Failed to grab focus on a Jtextfield Pin
Richard MacCutchan23-May-19 1:44
mveRichard MacCutchan23-May-19 1:44 
GeneralRe: Failed to grab focus on a Jtextfield Pin
Teressa Pirtle26-Dec-19 8:05
Teressa Pirtle26-Dec-19 8:05 
Questioncloudsim algorithm Genitic Pin
Member 1423906220-May-19 8:20
Member 1423906220-May-19 8:20 
AnswerRe: cloudsim algorithm Genitic Pin
Richard MacCutchan20-May-19 22:09
mveRichard MacCutchan20-May-19 22:09 
QuestionHow can i make Jtexfield updates when Jtable values are changed? Pin
User 140975918-May-19 2:36
User 140975918-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
mveRichard MacCutchan8-May-19 2:48 
GeneralRe: How can i make Jtexfield updates when Jtable values are changed? Pin
User 140975918-May-19 3:02
User 140975918-May-19 3:02 
GeneralRe: How can i make Jtexfield updates when Jtable values are changed? Pin
Richard MacCutchan8-May-19 3:19
mveRichard MacCutchan8-May-19 3:19 
Questionprogramation cloudsim java Pin
Member 142390627-May-19 0:06
Member 142390627-May-19 0:06 
AnswerRe: programation cloudsim java Pin
Eddy Vluggen7-May-19 0:32
professionalEddy Vluggen7-May-19 0:32 
GeneralRe: programation cloudsim java Pin
jschell18-May-19 7:01
jschell18-May-19 7:01 
QuestionRe: programation cloudsim java Pin
Eddy Vluggen18-May-19 8:29
professionalEddy Vluggen18-May-19 8:29 
AnswerRe: programation cloudsim java Pin
Richard MacCutchan18-May-19 20:56
mveRichard MacCutchan18-May-19 20:56 
GeneralRe: programation cloudsim java Pin
Eddy Vluggen18-May-19 22:42
professionalEddy Vluggen18-May-19 22:42 
GeneralRe: programation cloudsim java Pin
Richard MacCutchan19-May-19 1:05
mveRichard MacCutchan19-May-19 1:05 
GeneralRe: programation cloudsim java Pin
Eddy Vluggen19-May-19 1:19
professionalEddy Vluggen19-May-19 1:19 
GeneralRe: programation cloudsim java Pin
Richard MacCutchan19-May-19 1:45
mveRichard MacCutchan19-May-19 1:45 
GeneralRe: programation cloudsim java Pin
Eddy Vluggen19-May-19 8:58
professionalEddy Vluggen19-May-19 8:58 
GeneralRe: programation cloudsim java Pin
Richard MacCutchan19-May-19 21:15
mveRichard MacCutchan19-May-19 21:15 
AnswerRe: programation cloudsim java Pin
jschell23-May-19 5:35
jschell23-May-19 5:35 
GeneralRe: programation cloudsim java Pin
Eddy Vluggen23-May-19 23:36
professionalEddy Vluggen23-May-19 23:36 
QuestionWhat database shoud i pick for my java app? Pin
User 1409759129-Apr-19 7:42
User 1409759129-Apr-19 7:42 

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.