Code::
import javax.swing.*;
import java.awt.event.*;
public class Converter extends JFrame
{
JTextField t1 =new JTextField();
JTextField t2 =new JTextField();
JLabel l1=new JLabel("Celsius:");
JLabel l2=new JLabel("Fahrenheit:");
Converter()
{
setLayout(null);
setTitle("Converter");
setVisible(true);
setSize(400,200);
l1.setBounds(20,30,70,30);
l2.setBounds(20,70,70,30);
t1.setBounds(120,30,70,30);
t2.setBounds(120,70,70,30);
add(t1);
add(l1);
add(l2);
add(t2);
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(Double.parseDouble(t1.getText()))*1.8+32;
t2.setText(String.format("%.1f",a));
}
});
t2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(((Double.parseDouble(t2.getText()))-32)/1.8);
t1.setText(String.format("%.1f",a));
}
});
}
public static void main(String[] nt) {
new Converter();
}
}
import javax.swing.*;
import java.awt.event.*;
public class Converter extends JFrame
{
JTextField t1 =new JTextField();
JTextField t2 =new JTextField();
JLabel l1=new JLabel("Celsius:");
JLabel l2=new JLabel("Fahrenheit:");
Converter()
{
setLayout(null);
setTitle("Converter");
setVisible(true);
setSize(400,200);
l1.setBounds(20,30,70,30);
l2.setBounds(20,70,70,30);
t1.setBounds(120,30,70,30);
t2.setBounds(120,70,70,30);
add(t1);
add(l1);
add(l2);
add(t2);
t1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(Double.parseDouble(t1.getText()))*1.8+32;
t2.setText(String.format("%.1f",a));
}
});
t2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ double a=(((Double.parseDouble(t2.getText()))-32)/1.8);
t1.setText(String.format("%.1f",a));
}
});
}
public static void main(String[] nt) {
new Converter();
}
}
Output::