two problems

P

pageV

In this code bit:
void saveData()
{
String out;
try
{
//output = new BufferedWriter (file ) ;

try
{
out = Double.toString(index);
output.write( out + " ") ;
out = Double.toString(twoDig.format(total));
output.write( out + "\n");
}


}
catch( IOException ioe )
{
JOptionPane.showMessageDialog( null, "Err: " + ioe );
}
}
I commented out "output = new BufferedWriter (file ) ;" to move it outside
the method so I could write more than one line to the file. Also
moved the close statement outside the method so I could write more than one
line.
But it writes only the last line before I close it. That's the first
problem.
Then I added a line elsewhere in the program to change the look and feel
and the compiler started complaining about try without catch. So I commented
out one of the try's and a pair of brackets. Now I get

Coffee.java:188: cannot resolve symbol
symbol : method toString (java.lang.String)
location: class java.lang.Double
out = Double.toString(twoDig.format(total));
^
Put the try back in and get both errors.
Commented out the look and feel statement and still
get the errors. I can fix the try error but I can't
get back to where I was when the compiler accepted
the Double.toString.

Any solutions?
Ralph
 
C

Christophe Vanfleteren

pageV said:
In this code bit:
void saveData()
{
String out;
try
{
//output = new BufferedWriter (file ) ;

try
{
out = Double.toString(index);
output.write( out + " ") ;
out = Double.toString(twoDig.format(total));
output.write( out + "\n");
}


}
catch( IOException ioe )
{
JOptionPane.showMessageDialog( null, "Err: " + ioe );
}
}
I commented out "output = new BufferedWriter (file ) ;" to move it
outside the method so I could write more than one line to the file. Also
moved the close statement outside the method so I could write more than
one line.
But it writes only the last line before I close it. That's the first
problem.
Then I added a line elsewhere in the program to change the look and feel
and the compiler started complaining about try without catch. So I
commented
out one of the try's and a pair of brackets. Now I get

Coffee.java:188: cannot resolve symbol
symbol : method toString (java.lang.String)
location: class java.lang.Double
out = Double.toString(twoDig.format(total));
^
Put the try back in and get both errors.
Commented out the look and feel statement and still
get the errors. I can fix the try error but I can't
get back to where I was when the compiler accepted
the Double.toString.

Any solutions?
Ralph

Yes, there is no toString method that accepts a String in the Double class.

Looking at this might help you:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html

Your second try/catch block is also wrong: it is missing a catch statement,
which must always follow the try statement.
 
P

pageV

Christophe Vanfleteren said:
Yes, there is no toString method that accepts a String in the Double class.

Looking at this might help you:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html

Your second try/catch block is also wrong: it is missing a catch statement,
which must always follow the try statement.

I understand, I forget that twoDig.format made a string. The program works
now,
except I am still stuck with metal look and feel
UIManager.setLookAndFeel( new
com.sun.java.swing.plaf.windows.WindowsLookAndFeel() );
and
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName () );
don't seem to have an effect.

Earlier, i thought i was getting no errors, but the errors were scrolled off
the screen in Kawa, and all I saw was file compiled.

Thanks for the help
Ralph
 
C

Christophe Vanfleteren

pageV said:
I understand, I forget that twoDig.format made a string. The program
works now,
except I am still stuck with metal look and feel
UIManager.setLookAndFeel( new
com.sun.java.swing.plaf.windows.WindowsLookAndFeel() );
and
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName () );
don't seem to have an effect.

Earlier, i thought i was getting no errors, but the errors were scrolled
off the screen in Kawa, and all I saw was file compiled.

When are you calling this code? IIRC you should do this before you
initialize any Swing components.
 
P

pageV

Christophe Vanfleteren said:
When are you calling this code? IIRC you should do this before you
initialize any Swing components.

I had
JPanel jPanel1 = new JPanel(); and 17 similiar statements outside and
before the constructor. Changed it to Jpanel jpanl1 outside the constructor
and jPanel1= new JPanel(); inside and now I have Windows look and feel.
Thanks
Ralph
 
R

Roedy Green

you want something like this before you create any JFrames.

public static void main ( String[] args )
{
try
{
if ( Config.LOOK_AND_FEEL != null )
{
UIManager.setLookAndFeel( Config.LOOK_AND_FEEL );
}
ToolTipManager.sharedInstance().setInitialDelay( 1000 );
JFrame.setDefaultLookAndFeelDecorated ( true );
 
P

pageV

Roedy Green said:
you want something like this before you create any JFrames.

public static void main ( String[] args )
{
try
{
if ( Config.LOOK_AND_FEEL != null )
{
UIManager.setLookAndFeel( Config.LOOK_AND_FEEL );
}
ToolTipManager.sharedInstance().setInitialDelay( 1000 );
JFrame.setDefaultLookAndFeelDecorated ( true );

Tried it out. Didn't work until I noticed I had Kawa set to jdk1.3.
Worked fine on jdk1.4.

Ralph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top