
01)write a java program to add two integer variables and display the sum of them .using java swing
02)write a java program to find the surface of the sphere.Radius of the sphere may be any number that user gives.

Sum of two Numbers
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class SumOfNumbers extends JFrame
{
SumOfNumbers(){
JLabel lab1=new JLabel("Enter first number: ");
final JTextField text1=new JTextField(20);
JLabel lab2=new JLabel("Enter second number: ");
final JTextField text2=new JTextField(20);
JButton b=new JButton("Sum");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int num1=Integer.parseInt(text1.getText());
int num2=Integer.parseInt(text1.getText());
int sum=num1+num2;
JOptionPane.showMessageDialog(null,Integer.toString(sum));
}
});
JPanel p=new JPanel(new GridLayout(3,2));
p.add(lab1);
p.add(text1);
p.add(lab2);
p.add(text2);
p.add(b);
add(p);
setVisible(true);
setSize(300,100);
}
public static void main(String[] args)
{
new SumOfNumbers();
}
}
Surface Area of Sphere:
import java.util.*;
class SurfaceAreaOfSphere
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter radius: ");
double r =input.nextDouble();
double sarea = 4 * Math.PI * r*r;
System.out.println("Surface area: "+sarea);
}
}
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.