Java swing/awt inquiry

Hi all,

I'm trying to get a better hang of Java and Swing/AWT in general. I've written this piece of code to calculate area for the width/length of an office. Really simple just to understand the stuff at hand.  

I'm getting compile issues that look like the following:

$ javac OfficeAreaCalculator.java
OfficeAreaCalculator.java:84: OfficeAreaCalculator.calculateButtonHandler is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
      class calculateButtonHandler implements ActionListener
        ^
OfficeAreaCalculator.java:120: OfficeAreaCalculator.FocusHandler is not abstract and does not override abstract method focusLost(java.awt.event.FocusEvent) in java.awt.event.FocusListener
   class FocusHandler implements FocusListener
   ^
Note: OfficeAreaCalculator.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors


Anyone kind enough to point out what I'm doing incorrect?
import java.text.*; // need this for formatting
import javax.swing.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.*; // this is for layout management
 
public class OfficeAreaCalculator extends JFrame
{
	private JFrame mainFrame;
	private JButton calculateButton;
	private JButton exitButton;
	private JTextField lengthField;
	private JTextField widthField;
	private JTextField areaField;
	private JLabel lengthLabel;
	private JLabel widthLabel;
	private JLabel areaLabel;
                            
 
	public OfficeAreaCalculator()
	{
		mainFrame = new JFrame("Office Area Calculator");
	
		// create all components
		calculateButton 	= new JButton("Calculate area");
		exitButton			= new JButton("Exit");
		lengthLabel			= new JLabel("Enter the length of the office: ");
		widthLabel			= new JLabel("Enter the width of the office: ");
		areaLabel			= new JLabel("Office area: ");
		lengthField			= new JTextField(5);
		widthField			= new JTextField(5);
		areaField			= new JTextField(5);
	
		// get the content pane
		Container c = mainFrame.getContentPane();
	
		// set the layout manager
		c.setLayout(new FlowLayout());
	
		// add the components to the content pane
		c.add(lengthLabel);
		c.add(lengthField);
		c.add(widthLabel);
		c.add(widthField);
		c.add(areaLabel);
		c.add(areaField);
		c.add(calculateButton);
		c.add(exitButton);
 
	    // set size
		mainFrame.setSize(250,150);
	
		// define and register window event handler
		mainFrame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) { System.exit(0); }
		});
	
		// create and register the handlers
		calculateButtonHandler chandler = new calculateButtonHandler(); //instantiate new object
		calculateButton.addActionListener(chandler); // add event listener
	
		ExitButtonHandler ehandler = new ExitButtonHandler(); // instant a new handler
		exitButton.addActionListener(ehandler); // register the handler
	
		FocusHandler fhandler = new FocusHandler();
		lengthField.addFocusListener(fhandler);
		widthField.addFocusListener(fhandler);
		areaField.addFocusListener(fhandler);
	
		mainFrame.show();
	}   
	
	// classes for the button event handlers
	class calculateButtonHandler implements ActionListener
	{
		public void actionPerformed(Action e)
		{
			DecimalFormat num = new DecimalFormat(", ###.##");
			double width, length, area;
			String instring;
			
			instring = lengthField.getText();
			if (instring.equals(""))
			{
				instring = "0";
				lengthField.setText("0");
			}
			length = Double.parseDouble(instring);
			
			instring = widthField.getText();
			if (instring.equals(""))
			{
				instring = "0";
				widthField.setText("0");
			}                       
			width = Double.parseDouble(instring);
			area = length * width;
			areaField.setText(num.format(area));
		} 
	} // inner class ends here
	
   class ExitButtonHandler implements ActionListener
   {
   		public void actionPerformed(ActionEvent e)
		{
			System.exit(0);
		}
   }
 
   class FocusHandler implements FocusListener
   {
		public void focusGained(FocusEvent e)
		{
			if(e.getSource() == lengthField || e.getSource() == widthField)
			{
				areaField.setText("");
			}
			else if(e.getSource() == areaField)
			{
				areaField.setNextFocusableComponent(calculateButton);
				calculateButton.grabFocus();
			}
		}
		
		public void focusList(FocusEvent e)
		{
			if(e.getSource() == widthField)
			{
				widthField.setNextFocusableComponent(calculateButton);
			}
		}
   } // end focus listener class
 
   public static void main(String args[])
   {
   		new OfficeAreaCalculator();	//instantiage GUI
   }
}

Open in new window

LVL 3
stevefNYCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

contactkarthiCommented:
change

public void actionPerformed(Action e)

to

public void actionPerformed(ActionEvent e)


and

public void focusList(FocusEvent e)

to
public void focusLost(FocusEvent e)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stevefNYCAuthor Commented:
Silly overlooks on my behalf.  

Thanks karthi.  BTW, any chance of explaining what I'm using that's deprecated?

Note: OfficeAreaCalculator.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
0
contactkarthiCommented:
setNextFocusableComponent

and mainFrame.show(); are both deprecated
0
stevefNYCAuthor Commented:
I guess I'm reading an old book. :-( Is there something more reliable to read that's current, so I'm not using deprecated methods?
0
contactkarthiCommented:
if you use an ide it will point you out immediately. also you can google for the new alternatives for the deprecated ones.

http://java.sun.com/docs/books/tutorial/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.