first_panel = new Panel();
first_panel.setLayout(new FlowLayout());
second_panel = new Panel();
second_panel.setLayout(new FlowLayout());
third_panel = new Panel();
third_panel.setLayout(new FlowLayout());
first_panel.add(new Label("Enter the temperature in Fahrenheit:"));
first_panel.add(fahrenheitInput);
second_panel.add(convert);
third_panel.add(new Label("Here is the converted temperature in Celsius:"));
third_panel.add(celsiusInput);
// Add the panels to the applet.
add(first_panel);
add(second_panel);
add(third_panel);
}
public boolean action (Event evt, Object o)
{
// the event target once the button is clicked
if (evt.target == convert)
{
// Convert the temp and assign it to the celsius textfield
int f = Integer.parseInt(fahrenheitInput.getText());
int c = 5 * (f-32) / 9;
String newCelsius = Integer.toString(c);
celsiusInput.setText(newCelsius);
Probably best discussed in the applets forum. Moving.
LaTeef Lusk
Greenhorn
Joined: Mar 28, 2009
Posts: 15
posted
0
Adding in the action listener I am getting an error i dont understand.
c:\Temperature.java:5: Temperature is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionLis
tener
public class Temperature extends java.applet.Applet implements ActionListener ^
first_panel = new Panel();
first_panel.setLayout(new FlowLayout());
second_panel = new Panel();
second_panel.setLayout(new FlowLayout());
third_panel = new Panel();
third_panel.setLayout(new FlowLayout());
first_panel.add(new Label("Enter the temperature in Fahrenheit:"));
first_panel.add(fahrenheitInput);
second_panel.add(convert);
third_panel.add(new Label("Here is the converted temperature in Celsius:"));
third_panel.add(celsiusInput);
// Add the panels to the applet.
add(first_panel);
add(second_panel);
add(third_panel);
}
public boolean action (Event evt, Object o)
{
// the event target once the button is clicked
if (evt.target == convert)
{
// Convert the temp and assign it to the celsius textfield
int f = Integer.parseInt(fahrenheitInput.getText());
int c = 5 * (f-32) / 9;
String newCelsius = Integer.toString(c);
celsiusInput.setText(newCelsius);
when you implement ActionListener interface, you need to write the implementation of actionPerformed(ActionEvent e) method (see java documentation).
So your applet class should have that method's implementation, and you can put your button-clicked handler there.
♪♪♪ イルマ ♪♪♪
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35443
9
posted
0
Yes, the "public boolean action (Event evt, Object o)" method has been deprecated for more than 10 years; it should not be used. That's what ActionListeners are for.
hi, i'm trying to make a game with java applet. My problem is i need to make a "New Button". I already made the code but it isn't working (doesn't load the other class applet). Here is my source code :