Article View: borland.public.jbuilder.java.language
Article #19166Re: Saving Java programs settings?
From: James Rudnicki
Date: Fri, 27 Feb 1998 00:00
Date: Fri, 27 Feb 1998 00:00
109 lines
2764 bytes
2764 bytes
Dana Scott Kaufman wrote in message <34F6EFF8.F88BE2DD@ix.netcom.com>...
>What is the best way to save settings a Java program will use to
>configure itself each time it runs?
Use properties and .INI files. They are much like Win16/32 but there are no
sections, just
keys and values.
Here are some snips:
private void buildProperties
()
{
/* defaults for all properties
os - just in case */
Properties propDefault = new Properties();
propDefault.put( "searchbase", "." );
propDefault.put( "os", "Win32" );
propDefault.put( "bigshown", "false" );
propDefault.put( "bigsize", "12" );
propDefault.put( "bigtype", "ITALIC" );
propDefault.put( "known_n", "1" );
propDefault.put( "known_1", ".txt" );
propDefault.put( "viewPADonly", "false" );
m_Properties = new Properties( propDefault );
/* read file */
try
{
FileInputStream f = new FileInputStream("ProExplore.ini");
m_Properties.load( f );
}
catch( Exception e )
{}
return;
}
/* this is easy */
public void save()
{
try
{
FileOutputStream f = new FileOutputStream("ProExplore.ini");
m_Properties.save( f, "hehe" );
}
catch( Exception e )
{}
return;
}
/* give access to applications properties to a frame for instance */
public Properties getAppProperties() {
return m_Properties;
}
/* use them in a dialog */
public Frame1( Explore app )
{
String sWork;
m_Parent = app;
sWork = m_Parent.getAppProperties().getProperty("viewPADonly");
m_bShowOnlyPAD = Boolean.valueOf( sWork ).booleanValue();
sWork = m_Parent.getAppProperties().getProperty("bigshown");
m_bViewBigFont = Boolean.valueOf( sWork ).booleanValue();
/* ..... */
return;
}
/* save them in exit of frame */
private void saveProperties()
{
String sWork;
sWork = (new Boolean( m_bViewBigFont )).toString();
m_Parent.getAppProperties().put( "bigshown", sWork );
sWork = (new Boolean( m_bShowOnlyPAD )).toString();
m_Parent.getAppProperties().put( "viewPADonly", sWork );
m_Parent.save();
return;
}
bye,
Jim
Technical Details
Message-ID:
<6d8bfn$9qe2@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<34F6EFF8.F88BE2DD@ix.netcom.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,bde2fada64d4d4f8 X-Google-Attributes: gidf74b3,public From: "James Rudnicki" <rudnicki@best.com> Subject: Re: Saving Java programs settings? Date: 1998/02/27 Message-ID: <6d8bfn$9qe2@forums.borland.com> X-Deja-AN: 329387165 References: <34F6EFF8.F88BE2DD@ix.netcom.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language