0

I just want to know how to implement an interface in an inner class. I have to make an interface called tConvertMethods and then implement that in the inner class.

You will be doing the event-handling operations using an inner class, have the inner class implement tConvertMethods interface as well as having it implement ActionListener inferface.

user2680602
  • 33
  • 1
  • 5
  • 3
    And what is your problem with this? – nachokk Aug 14 '13 at 00:35
  • 1
    Yes, please define your actual problem. Also as an aside, you will want to learn and follow Java naming conventions, including using upper case for the first letter of all classes and interfaces. This will help make it easier for others to understand your code. – Hovercraft Full Of Eels Aug 14 '13 at 00:35
  • I think, he just needs to know the syntax of implementing interfaces in the inner class, as OP mentions, I just want to know how to implement an interface in an inner class. – JNL Aug 14 '13 at 00:37
  • -1 for not explaining what the problem is in the OP's code. – SevenBits Aug 14 '13 at 00:42
  • sorry, this is my first time posting. I didn't know where to put the tConvertMethods. – user2680602 Aug 14 '13 at 00:46
  • @user2680602: rather than apologizing, consider improving your question. – Hovercraft Full Of Eels Aug 14 '13 at 00:49
  • If you are asking how to code the tConvertMethods, we don't know because we do not know what they are supposed to do. Does tConvert change an Int to String, or some class of yours to some other class. We need more information about your problem in order to help you. – mwjohnson Aug 14 '13 at 00:51
  • If this answers your question, mark the answer. If not please clarify more where you are confused. – mwjohnson Aug 14 '13 at 01:22
  • I believe for StackOverflow (SO) the preferred approach to your situation is to create a new question, and leave the original. As the title and tags are no longer related to your new question, but are still relevant from your previous question. Your question now is about how to handle the logic of your if statements, not how to use an inner class. That way when people perform searches only relevant information is presented. – mwjohnson Aug 14 '13 at 05:52

2 Answers2

2

You can implement multiple interfaces in Java.

If ButtonHandler is your inner class.

private class ButtonHandler implements ActionListener, tConvertMethods{
    // Your code here

}

Go through this.

JNL
  • 4,683
  • 18
  • 29
2

Perhaps something like this response: How to add action listener that listens to multiple buttons is what you are looking for? There is nothing wrong with the code you provided. None of us knows what tConvert is supposed to do, or what you want your ButtonHandler class to do, so we can't tell you how to code those classes or methods.

You've almost got it, the next step is to perform your calculation...

Use the equation: °C x 9/5 + 32 = °F

So we are calculating for Farenheit. The user provides the degress in Celsius, which you have, celsValue. So...

fahrValue = (9.0/5.0)*celsValue + 32;

presumably you then want to print that fahrValue.

fahrString = fahrValue.ToString();
Community
  • 1
  • 1
mwjohnson
  • 661
  • 14
  • 26
  • 1
    I see. In the original (9/5) is two `ints`, so the answer of that component always evaluates to 1. Where we actually want 1.8, so by using 9.0/5.0 we get the desired response. I have fixed the answer. – mwjohnson Aug 14 '13 at 02:24