'unreported exception java.io.IOException; must be caught or declared to be thrown


Joined
Oct 8, 2009
Messages
1
Reaction score
0
can someone please help me?.. i can't solve this error which state 'unreported exception java.io.IOException; must be caught or declared to be thrown'. i really appreciate if u guys can explain it to me.. :veryprou:

my code is as follow...

Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;

public class Question1 extends JFrame {

	private JLabel label1, label2;
	private JTextField text1, text2;
	private Container c;
	private GridLayout grid1;

	public Question1() {
	
		super("Mile to Km / Km to Mile");
		Container c = getContentPane();
		grid1 = new GridLayout( 2, 2 );
		c.setLayout(grid1);
		
		label1 = new JLabel("Mile");
		c.add(label1);

		text1 = new JTextField(10);
      		c.add(text1);

		label2 = new JLabel("Kilometer");
		c.add(label2);

		text2 = new JTextField(10);
      		c.add(text2);

		TextFieldHandler handler = new TextFieldHandler();
      		text1.addActionListener(handler);
      		text2.addActionListener(handler);
		
		setSize(325,100);
		setVisible(true);

	}

	public static void main(String[] args) {

		Question1 app = new Question1();

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		float miles = Float.parseFloat(bf.readLine());
		float km = miles * 1.609344f;

		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

	private class TextFieldHandler implements ActionListener {

      		public void actionPerformed(ActionEvent e) {

			String string = "";

         		// user pressed Enter in JTextField text1
         		if (e.getSource() == text1)
            		string = "text1: " + e.getActionCommand();

         		// user pressed Enter in JTextField text2
        		else if (e.getSource() == text2)
            		string = "text2: " + e.getActionCommand();
	
         		// user pressed Enter in JTextField text3
         		else
            		string = "Do not try to test my intelligence!";
         }

         //JOptionPane.showMessageDialog(null, string);
      }

   //}  // end private inner class TextFieldHandler

}
 
Ad

Advertisements


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

Top