Link to home
Start Free TrialLog in
Avatar of gbcbr
gbcbrFlag for Cyprus

asked on

Reading from text fields

After some exercising with logging now it stop write into dcc.properties file and delete all values from it.
When I put in new values into dcc.properties directly and when I start app it prints this values well, but when I change them, file still have old values.
Everything was working like watch, what may happened.
I even come back with Subversion, but I didn't find any critical changes into the code, reload JDeveloper - nothing!
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

gui.ser was there when i last looked;)

Logging is not really connected with the problem most probably. You just need to ensure the the file saving method is called - why not add some logging to see what's happening?
Avatar of gbcbr

ASKER

dcc.properties
#Sat Mar 26 18:31:41 EET 2011
eurusd_support=1.39
eurusd_resist=1.42
eurjpy_resist=1
eurchf_support=1
eurgbp_support=1
usdchf_resist=1
chfjpy_resist=1
eurjpy_support=1
gbpusd_resist=1
gbpjpy_resist=1
eurchf_resist=1
gbpchf_support=1
eurgbp_resist=1
gbpjpy_support=1
gbpchf_resist=1
usdjpy_support=1
gbpusd_support=1
chfjpy_support=1
usdchf_support=1
usdjpy_resist=1

Open in new window

Exit
void fileExit_ActionPerformed() {
        mFxcmGateway.logout();
        windowClosing();
        System.exit(0);
    }

    public void windowClosing() {
        OutputStream out = null;

        try {
            Properties prop = new Properties();
            out = new FileOutputStream("dcc.properties");

            System.out.println(" FileOutputStream = " + out);

            prop.setProperty("eurusd_support", eurusd_support);
            prop.setProperty("eurusd_resist", eurusd_resist);
            prop.setProperty("eurchf_support", eurchf_support);
            prop.setProperty("eurchf_resist", eurchf_resist);
            prop.setProperty("eurgbp_support", eurgbp_support);
            prop.setProperty("eurgbp_resist", eurgbp_resist);
            prop.setProperty("usdchf_support", usdchf_support);
            prop.setProperty("usdchf_resist", usdchf_resist);
            prop.setProperty("gbpusd_support", gbpusd_support);
            prop.setProperty("gbpusd_resist", gbpusd_resist);
            prop.setProperty("gbpchf_support", gbpchf_support);
            prop.setProperty("gbpchf_resist", gbpchf_resist);
            prop.setProperty("eurjpy_support", eurjpy_support);
            prop.setProperty("eurjpy_resist", eurjpy_resist);
            prop.setProperty("usdjpy_support", usdjpy_support);
            prop.setProperty("usdjpy_resist", usdjpy_resist);
            prop.setProperty("gbpjpy_support", gbpjpy_support);
            prop.setProperty("gbpjpy_resist", gbpjpy_resist);
            prop.setProperty("chfjpy_support", chfjpy_support);
            prop.setProperty("chfjpy_resist", chfjpy_resist);


            System.out.println(" eurusd_resist = " + eurusd_resist);
            System.out.println(" eurusd_support = " + eurusd_support);
            
            prop.store(out, null);
        } catch (IOException ex) {
            Logger.getLogger(DCC.class.getName()).log(Level.SEVERE,
                                                                          null,
                                                                          ex);

        } finally {
            try {
                if (out != null)
                    out.close();
            } catch (Exception ex) {
                Logger.getLogger(DCC.class.getName()).log(Level.SEVERE, null,
                                                          ex);
            }
        }
    }

Open in new window

Calling getText
public String getTextresistEURUSD() {
        eurusd_resist = resistance_EURUSD.getText();
                System.out.println("    DCC  resistance_EURUSD = " + eurusd_resist);
        return eurusd_resist;
    }

    public String getTextsupportEURUSD() {
        eurusd_support = support_EURUSD.getText();
        //        System.out.println("    DCC  support = " + support);
        return eurusd_support;
    }

    public String getTextresistEURCHF() {
        eurchf_resist = resistance_EURCHF.getText();
        //        System.out.println("    DCC  resist = " + resist);
        return eurchf_resist;
    }

    public String getTextsupportEURCHF() {
        eurchf_support = support_EURCHF.getText();
        //        System.out.println("    DCC  support = " + support);
        return eurchf_support;
    }

Open in new window

Output
FileOutputStream = java.io.FileOutputStream@700de5f5
 eurusd_resist = 1.42
 eurusd_support = 1.39
Process exited.

Open in new window

I change values but they not getted-recorded
But loading from dcc.properties it's OK
Yesterday everything work perfect. Why it stop reading?
resistance_EURUSD.setPreferredSize(new Dimension(80, 30));
        resistance_EURUSD.setBackground(new Color(181, 255, 181));
        resistance_EURUSD.setHorizontalAlignment(JTextField.CENTER);
//        resistance_EURUSD.setText("1.4280"); // Resistanse level
        resistance_EURUSD.setText(applicationProps.getProperty("eurusd_resist")); // Resistanse level
        resistance_EURUSD.setFont(new Font("Lucida Grande", 0, 12));
        resistance_EURUSD.requestFocusInWindow();
        resistance_EURUSD.setName("resistance_EURUSD");

Open in new window

Make sure you're reading and writing to the file think you are
Avatar of gbcbr

ASKER

What you mean? I have only one dcc.properties and whatever I write into this file directly appear on the screen.
Problem, as I see that this method  
public String getTextresistEURUSD() {
        eurusd_resist = resistance_EURUSD.getText();
                System.out.println("    DCC  resistance_EURUSD = " + eurusd_resist);
        return eurusd_resist;
    }

Open in new window

doesn't get real value from the field, so finally it gets value which was settled from dcc.p this is the reason why we have this output:
out = new FileOutputStream("dcc.properties");

            System.out.println(" FileOutputStream = " + out);

            prop.setProperty("eurusd_support", eurusd_support);
            prop.setProperty("eurusd_resist", eurusd_resist);
.....................
            System.out.println(" eurusd_resist = " + eurusd_resist);
            System.out.println(" eurusd_support = " + eurusd_support);


>>>>>>>>>>>>>>
FileOutputStream = java.io.FileOutputStream@700de5f5
 eurusd_resist = 1.42
 eurusd_support = 1.39

Open in new window

Avatar of gbcbr

ASKER

I even change dcc.p to dcc2.p and it's create exact copy of dcc
Avatar of gbcbr

ASKER

I found that something wrong with recording.
If I delete any line from dcc.p and start app this field shows empty, but when I try to close app via Exit it shows:
FileOutputStream = java.io.FileOutputStream@8a85268
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:394)
	at java.util.Properties.setProperty(Properties.java:143)
	at control.DCC.windowClosing(DCC.java:2304)
	at control.DCC.fileExit_ActionPerformed(DCC.java:2279)
	at control.DCC$2.actionPerformed(DCC.java:439)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:389)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:809)
	at com.apple.laf.AquaMenuItemUI.doClick(AquaMenuItemUI.java:137)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:850)
	at java.awt.Component.processMouseEvent(Component.java:6374)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
	at java.awt.Component.processEvent(Component.java:6139)
	at java.awt.Container.processEvent(Container.java:2085)
	at java.awt.Component.dispatchEventImpl(Component.java:4736)
	at java.awt.Container.dispatchEventImpl(Container.java:2143)
	at java.awt.Component.dispatchEvent(Component.java:4566)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4282)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
	at java.awt.Container.dispatchEventImpl(Container.java:2129)
	at java.awt.Window.dispatchEventImpl(Window.java:2478)
	at java.awt.Component.dispatchEvent(Component.java:4566)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:680)
	at java.awt.EventQueue.access$000(EventQueue.java:86)
	at java.awt.EventQueue$1.run(EventQueue.java:639)
	at java.awt.EventQueue$1.run(EventQueue.java:637)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
	at java.awt.EventQueue$2.run(EventQueue.java:653)
	at java.awt.EventQueue$2.run(EventQueue.java:651)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:650)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Open in new window

and I can't exit normally.
When I cancel in force it delete whole content of dcc.p and next time I can't start.
>>If I delete any line from dcc.p and start app this field shows empty

Don't do that, it will cause the field to be null. If the field isn't found on load, you should initialize the text field to an empty string
Avatar of gbcbr

ASKER

And this at control.DCC.windowClosing(DCC.java:2304) is prop.setProperty("eurjpy_support", eurjpy_support);
line deleted from dcc.properties, so it doesn't create new record
Avatar of gbcbr

ASKER

I make like this
resistance_EURUSD.setText("1.4280"); // Resistanse level
//        resistance_EURUSD.setText(applicationProps.getProperty("eurusd_resist")); // Resistanse level

Open in new window

and comment this line it dcc.
It shows settled value and save it into dcc, but if I change value, anyway it save in dcc old value.
Something wrong with reading after typing, it's read well settled in any way value: or from dcc.p or direct setting, but all typing are ignored.
objects will be along later: he suggested doing this the hard way
Avatar of gbcbr

ASKER

I'll attach now DCC.java
You have old one, please check what it maybe the difference.
But, as I told before, I check in Subversion, but I didn't find anything critical.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gbcbr

ASKER

Yes, thank you, this is's work, but why it perfect works before with old construction and now stops?
no idea sorry, not sure what you changed before
Avatar of gbcbr

ASKER

@objects
http:#35197346
just for understanding root of problem, what is the possible reason this break?
you were previously updating the variables that you were using
Avatar of gbcbr

ASKER

@objects
please clarify
previously you must have been updating the value oif the eurusd_support variable to be what was in the text field
Avatar of gbcbr

ASKER

ok, anyway I think this way much straight and reliable.