jLabel无法从属性文件更新

问题描述

我有一个jframe“ Rest.java”包含空的jlabel,一个btn用来打开新的jframe参数“ Restparametre.java”包含JtextFiels,用户可以在其中编写(文章和价格),并且bnt保存以首先在jLabels中进行更新jFrame“ Rest.java”。 我用于此属性。但是我在代码中有两个问题

  1. 如果我不关闭应用程序,则第一个Jframe不会使用新添加的jlabel更新。

  2. jLabels文本未正确更改(有时更改,有时不更改) 这是我使用的代码..

    
         try{
       configFile = new File("config.properties");
       fis = new FileInputStream(configFile);
    
      Properties propConfig;
            propConfig = new Properties();
     propConfig.load(fis);
     String st  = propConfig.getProperty("article");
    
    
     jLabel1.setText(st);
    
    jLabel1.repaint();
    
    
     String stre = propConfig.getProperty("prix");
    
     jLabel2.setText(stre);
     jLabel2.repaint();
    
    
     System.out.println(st);
     System.out.println(stre);
    
    
    
     fis.close();
    
    
       }
    
       catch(Exception e){e.printstacktrace();
       }
    
    
    

和Restparametre.java代码

  ```
    public class Restparametre extends javax.swing.JFrame {
     File ConfigFile = null;
       public Restparametre() {
         initComponents();
        } 
         private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         


    String msg = jTextField2.getText();
    String str= jTextField3.getText();

    double dnum = Double.parseDouble(str);


     FileOutputStream fos = null;
   //File ConfigFile = null;

     try{ 
  File configFile = new File("config.properties");
  fos = new FileOutputStream(configFile);
  Properties propConfig = new Properties();
  
  propConfig.setProperty("article",msg);
  propConfig.setProperty("prix",String.valueOf(dnum));
  
  propConfig.store(fos,"restaurant papametre");
  fos.close();
  
    }
      catch(Exception e){
       e.printstacktrace();
      }



 
     new Rest().setVisible(true);
    this.setVisible(false);
   
   }                                        

     private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                            
       // Todo add your handling code here:
    }                                           


    public static void main(String args[]) {
   
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : 
       javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
       } catch (ClassNotFoundException ex) {
        
 
 
 
 
java.util.logging.Logger.getLogger(Restparametre.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
    } catch (InstantiationException ex) {
        
 
 
java.util.logging.Logger.getLogger(Restparametre.class.getName()).log(java.util.logging.Level.SEVERE,ex);
    } catch (illegalaccessexception ex) {
        
 java.util.logging.Logger.getLogger(Restparametre.class.getName()).log(java.util.logging.Level.SEVERE,ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        
 java.util.logging.Logger.getLogger(Restparametre.class.getName()).log(java.util.logging.Level.SEVERE,ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokelater(new Runnable() {
        public void run() {
            new Restparametre().setVisible(true);
        }
    });
}


  ```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)