Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 19th, 2005, 2:30 PM   #1
chrome_knob
Newbie
 
Join Date: Apr 2005
Posts: 3
Rep Power: 0 chrome_knob is on a distinguished road
exception handling

Here's the basic structure of my program

import stuff;
-----------------------------------------------
public class MapImage extends JFrame {

 public MapImage()
 {
  super( "Mapped Image" );

  setSize( 400, 165 );
  show();
 }
-----------------------------------------------
 public void paint( Graphics g )
 {

 }
-----------------------------------------------
 public static void main( String args[] )
 {
  MapImage app = new MapImage();

  app.addWindowListener(
   new WindowAdapter() {
    public void windowClosing( WindowEvent e )
    {
     System.exit( 0 );
    }
   }
  );
 }
}

The second method, public void paint, is the problem. I've left it blank because it's fairly long but I'll bring up the important parts here. First I open a file for input.

  File inputFile = new File( "map.gz" );
  FileInputStream in = new FileInputStream( inputFile );

Then I read the first three byte values of the file and use them to set the color.

g.setColor( new Color( c[0], c[1], c[2] ) );

I have a pixel drawn on the screen.

g.drawLine( x,y,x,y );

Then I read the next three bytes of the file to get the next color and print the next pixel untill the entire file has been read. I'm left with a graphical representation of the file where each pixel represents three bytes. Then

in.close();

But when I try to compile it I get these:

unreported exception java.io.FileNotFoundException
unreported exception java.io.IOException

Where do I need to type in the "throws IOException" statement in order to fix this? I've tried it at the end of all three methods but still get the same problem.
chrome_knob is offline   Reply With Quote
Old May 19th, 2005, 4:23 PM   #2
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 148
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
put the code where your opening the file into a try statement, like this.
try {
  File inputFile = new File( "map.gz" );
  FileInputStream in = new FileInputStream( inputFile );
} catch(Exception e) {
  System.out.println(e);
  System.exit(1);
}
ZenMasterJG is offline   Reply With Quote
Old May 19th, 2005, 5:45 PM   #3
chrome_knob
Newbie
 
Join Date: Apr 2005
Posts: 3
Rep Power: 0 chrome_knob is on a distinguished road
Thanks. It worked.
chrome_knob is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC