import
java.awt.*;
import
java.awt.event.*;
import
javax.swing.*;
public
class
SApplet
extends
JApplet
implements
ActionListener {
JTextField num1, num2, res;
JButton resBtn;
public
void
init()
{
num1 =
new
JTextField(
5
);
num2 =
new
JTextField(
5
);
res =
new
JTextField(
10
);
res.setEditable(
false
);
resBtn =
new
JButton(
"Multiply"
);
resBtn.addActionListener(
this
);
JLabel l1 =
new
JLabel(
"Enter Number 1:"
);
JLabel l2 =
new
JLabel(
"Enter Number 2:"
);
JLabel l3 =
new
JLabel(
"Result:"
);
l1.setForeground(Color.black);
l2.setForeground(Color.black);
l3.setForeground(Color.black);
JPanel pan =
new
JPanel();
pan.setLayout(
new
GridLayout(
4
,
2
));
pan.add(l1);
pan.add(num1);
pan.add(l2);
pan.add(num2);
resBtn.setBackground(Color.orange);
pan.add(resBtn);
pan.add(
new
JLabel());
pan.add(l3);
pan.add(res);
pan.setForeground(Color.black);
Font lfont = l1.getFont();
Font inFont = lfont.deriveFont(Font.PLAIN,
20
);
l1.setFont(inFont);
l2.setFont(inFont);
l3.setFont(inFont);
num1.setFont(inFont);
num2.setFont(inFont);
res.setFont(inFont);
resBtn.setFont(inFont);
setLayout(
new
BorderLayout());
add(pan, BorderLayout.CENTER);
}
public
void
actionPerformed(ActionEvent e){
if
(e.getSource() == resBtn) {
String str1 = num1.getText();
String str2 = num2.getText();
try
{
int
num1 = Integer.parseInt(str1);
int
num2 = Integer.parseInt(str2);
int
result = num1 * num2;
res.setText(Integer.toString(result));
}
catch
(NumberFormatException ex) {
res.setText(
"Wrong Input"
);
}
}
}
}