Whats that paint job doing in there ? You must deliver
the answer in another TextField by the setText() method.
Your main is only for testing, if it is an applet. here is
a way:
Code:
public static void main(String[] args) {
NumberSystem ns=new NumberSystem();
ns.init();
Frame f=new Frame();
f.setTitle("Testing NumberSystem Applet");
f.setLayout(new BorderLayout());
f.add(ns,BorderLayout.CENTER);
Button closeBtn=new Button("Close");
f.add(closeBtn,BorderLayout.SOUTH);
closeBtn.addActionListener(ns);
f.setVisible(true);
f.pack();
}
then you test for the Close button in your applets
actionPerformed() like
Code:
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand().equals("Close")) System.exit(0); // not for a real applet...
// must be calculate btn
try {
calculate();
}
catch (NumberFormatException ex) {
messageLbl.setText("Invalid number entry");
}
}
and change your
and perform your calculation in a method like
Code:
private void calculate() throws NumberFormatException {
int base=Integer.parseInt(this.baseField.getText().trim()); // throws for bad number
String numStr=this.numberField.getText().trim();
.
.
}
Bookmarks