Vasile1991
Programmer
Hello,
I'm doing an arithmetic expression calculator as an applet and I have encountered a problem... It's not crucial that this problem would be solved but if it can be solved it would make my applet better. So, I'm relatively new to Java (Java only) and I'd like to add a KeyListener so that when I press a numeric button, that number would appear in a textfield I've got to make the calculations afterwards.
I have 2 classes, one is :
class ExpressionCalculatorApplet extends Applet { ... } in which I have the method init and another class,
ExpressionCalculatorG extends JPanel implements ActionListener, KeyListener {...}
I have added the unimplemented methods and then have changed them.
So far I wanted only to see it works so that when I press a certain key that key would appear as the textfield's text.
public void keyTyped(KeyEvent e) {
expField.setText("" + e.getKeyChar());
expField.repaint();
}
where ExpField is that textfield I've been speaking of.
In ExpressionCalculatorS I have multiple panels, I can add KeyListeners to them? I wrote this :
this.addKeyListener(this); in the ExpressionCalculatorG class. Still doesn't work... any suggestions, please of what could be wrong?
Thank you,
Vasile.
I'm doing an arithmetic expression calculator as an applet and I have encountered a problem... It's not crucial that this problem would be solved but if it can be solved it would make my applet better. So, I'm relatively new to Java (Java only) and I'd like to add a KeyListener so that when I press a numeric button, that number would appear in a textfield I've got to make the calculations afterwards.
I have 2 classes, one is :
class ExpressionCalculatorApplet extends Applet { ... } in which I have the method init and another class,
ExpressionCalculatorG extends JPanel implements ActionListener, KeyListener {...}
I have added the unimplemented methods and then have changed them.
So far I wanted only to see it works so that when I press a certain key that key would appear as the textfield's text.
public void keyTyped(KeyEvent e) {
expField.setText("" + e.getKeyChar());
expField.repaint();
}
where ExpField is that textfield I've been speaking of.
In ExpressionCalculatorS I have multiple panels, I can add KeyListeners to them? I wrote this :
this.addKeyListener(this); in the ExpressionCalculatorG class. Still doesn't work... any suggestions, please of what could be wrong?
Thank you,
Vasile.