Java programming help...again

MorningWood

New Member
I cant figure out these questions and how to rewrite this program to add conversions to do Kilometeres to Miles, instead of being Miles to Kilometeres.

Questions.

1. Explain why there is no main()

2. What are {} used for?

3. Explain Label and TextField

4. explain getText()

Coding that has to be converted to KM - MI below.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Proj1_1 extends Applet implements ActionListener
{
double MI, KM;
Label prompt;
TextField input;

public void init()
{
prompt = new Label ("Enter the number of miles you've run: ");
add(prompt);

input = new TextField(5);
add(input);

input.addActionListener(this);
}
public void actionPerformed (ActionEvent e)
{
MI = Integer.parseInt(input.getText());
KM = MI / .62;
repaint();
}

public void paint (Graphics g)
{
g.drawString ("You have run " + KM + " kilometers.", 70, 75);
}
}





Any help would be greatly appreciated....
 

footballstevo75

Active Member
I cant figure out these questions and how to rewrite this program to add conversions to do Kilometeres to Miles, instead of being Miles to Kilometeres.

Questions.

1. Explain why there is no main()

2. What are {} used for?

3. Explain Label and TextField

4. explain getText()

Coding that has to be converted to KM - MI below.
There is no main because the class is probably accessed from a different class.

Label and TextField are objects which you create instances on that one, but don't quote me on that I'm tired.

Get text is a method.

It's not that hard to switch the formula around either. I believe this is HW here? Do you understand what's going on here? You should really look at inheritance and interfaces to understand what is going on.
 

MorningWood

New Member
^ thanks. Well I imagine you just switch the coding around, right? Instead of having MI first, you just put the KM first?
 
Top