7 replies
by pmdvs
by okujava
hi! the problem ist, that ie doesn't support swing. u must install plugin from sun or use not swing classes. no components with "J" should be in your applet ...
the url for plugin:
http://java.sun.com/getjava/download.html
by pmdvs
Yes. As I explained I already figured that out. The trouble is also happening with the Applet class. Specifically here, the Applet loads (this is directly from a tutorial) but the "Add" functionality does not work in my browser. It works fine in theapplet viewer, so I know the code logic is ok.
// applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class OlderAdderApplet extends Applet implements ActionListener
{
private TextField inputOutputField; private double sum = 0;
public void init()
{
setLayout(new BorderLayout());
Panel buttonPanel = new Panel();
buttonPanel.setBackground(Color.gray);
buttonPanel.setLayout(new FlowLayout()); Button addButton = new Button("Add");
addButton.addActionListener(this);
buttonPanel.add(addButton);
Button resetButton = new Button("Reset");
resetButton.addActionListener(this);
buttonPanel.add(resetButton);
add(buttonPanel, BorderLayout.SOUTH);
Panel textPanel = new Panel();
textPanel.setBackground(Color.blue);
textPanel.setLayout(new FlowLayout());
inputOutputField = new TextField("Numbers go here.", 30);
inputOutputField.setBackground(Color.white);
textPanel.add(inputOutputField);
add(textPanel, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("Add"))
{
sum = sum +
stringToDouble(inputOutputField.getText());
inputOutputField.setText(Double.toString(sum));
}
else if (e.getActionCommand().equals("Reset"))
{ sum = 0;
inputOutputField.setText("0.0");
}
else
inputOutputField.setText("Error in adder code.");
}
private stat
by pmdvs
Here's the full code (didn't fit in my other comment)
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class OlderAdderApplet extends Applet implements ActionListener
{
private TextField inputOutputField;
private double sum = 0;
public void init()
{
setLayout(new BorderLayout());
Panel buttonPanel = new Panel();
buttonPanel.setBackground(Color.gray);
buttonPanel.setLayout(new FlowLayout());
Button addButton = new Button("Add");
addButton.addActionListener(this);
buttonPanel.add(addButton);
Button resetButton = new Button("Reset");
resetButton.addActionListener(this);
buttonPanel.add(resetButton);
add(buttonPanel, BorderLayout.SOUTH);
Panel textPanel = new Panel();
textPanel.setBackground(Color.blue);
textPanel.setLayout(new FlowLayout());
inputOutputField = new TextField("Numbers go here.", 30);
inputOutputField.setBackground(Color.white);
textPanel.add(inputOutputField);
add(textPanel, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("Add"))
{
sum = sum +
stringToDouble(inputOutputField.getText());
inputOutputField.setText(Double.toString(sum));
}
else if (e.getActionCommand().equals("Reset"))
{ sum = 0;
inputOutputField.setText("0.0");
}
else
inputOutputField.setText("Error in adder code.");
}
private static double stringToDouble(String stringObject)
{
return Double.parseDouble(stringObject.trim());
}
}
by okujava
the problem is the parseDouble method call in
private static double stringToDouble(String stringObject)
{
return Double.parseDouble(stringObject.trim());
}
}
the method doesn't exist in jdk version 1.1.X
change it to:
return new Double(stringObject.trim()).doubleValue();
hope it helps.
P.S. if u move over the applet with your mouse, u should see a message in the status bar. what does it say?
by pmdvs
Yes! Thanks you very much. That did the trick.
-pam
by pmdvs
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending