
How can i create multiple labels using AWT????

Java Applet Example multiple labels
1)AppletExample.java:
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class AppletExample extends Applet implements ActionListener {
TextField input1,input2,output;
Label label1,label2,label3;
Button b1;
int num1,num2, sum = 0;
public void init(){
label1 = new Label("Number 1: ");
add(label1);
input1 = new TextField(5);
add(input1);
label2 = new Label("Number 2: ");
add(label2);
input2 = new TextField(5);
add(input2);
label3 = new Label("Sum : ");
add(label3);
output = new TextField(10);
add(output);
b1 = new Button("Add");
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
try{
num1 = Integer.parseInt(input1.getText());
num2 = Integer.parseInt(input2.getText());
sum = num1+num2;
output.setText(Integer.toString(sum));
}
catch(NumberFormatException e){
}
}
}
2)applet.html:
<HTML> <BODY> <APPLET ALIGN="CENTER" CODE="AppletExample.class" width = "260" height = "200"></APPLET> </BODY> </HTML>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.