(A) Complete the program by writing appropriate statements in the places indicated so that the program produces a GUI.
(Note: There are at most 8 statements missing in the main program and 2 import statements are missing.) what I did is indicated by the comments, there are some spaces that i couldnt fill up.
this is what i did:
import javax.swing.*;
import java.awt.event. ActionListener;
import java.awt.event. ActionEvent;
public class TempConvertGUI extends JFrame implements ActionListener{
JTextField TF;
JButton B;
JPanel P;
JLabel L,result;
float temp;
public TempConvertGUI( ){
B =new JButton("conver t"); //1
L=new JLabel("Enter Temp in Celsius");
TF=new JTextField(5);
P= new JPanel(); //2
result=new JLabel(" ");
L=new JLabel("Temp in Fahrienheit"); //3
P.add(L);
P.add(TF);
P.add(B);
P.add(result);
this.getContent Pane().add(P);
ActionListener listener = new ClickListener() ; //4
this.setSize(30 0,300);
B.addActionList ener(listener); //5
}
public void actionPerformed (ActionEvent arg0) {
//6
temp=9*temp/5+32;
// 7
}
public static void main(String[] args) {
TempConvertGUI TC = new TempConvertGUI( );//8
//9
}
Thanks for all your help
(Note: There are at most 8 statements missing in the main program and 2 import statements are missing.) what I did is indicated by the comments, there are some spaces that i couldnt fill up.
Code:
-----------
---------------
public class TempConvertGUI extends JFrame implements ActionListener{
JTextField TF;
JButton B;
JPanel P;
JLabel L,result;
float temp;
public TempConvertGUI(){
------------------------------
L=new JLabel("Enter Temp in Celsius");
TF=new JTextField(5);
------------------------------
result=new JLabel(" ");
-----------------
P.add(L);
P.add(TF);
P.add(B);
P.add(result);
this.getContentPane().add(P);
------------------------------
this.setSize(300,300);
-------------
}
public void actionPerformed(ActionEvent arg0) {
---------------
temp=9*temp/5+32;
--------------------
}
public static void main(String[] args) {
-----------------------
-----------------------
}
import javax.swing.*;
import java.awt.event. ActionListener;
import java.awt.event. ActionEvent;
public class TempConvertGUI extends JFrame implements ActionListener{
JTextField TF;
JButton B;
JPanel P;
JLabel L,result;
float temp;
public TempConvertGUI( ){
B =new JButton("conver t"); //1
L=new JLabel("Enter Temp in Celsius");
TF=new JTextField(5);
P= new JPanel(); //2
result=new JLabel(" ");
L=new JLabel("Temp in Fahrienheit"); //3
P.add(L);
P.add(TF);
P.add(B);
P.add(result);
this.getContent Pane().add(P);
ActionListener listener = new ClickListener() ; //4
this.setSize(30 0,300);
B.addActionList ener(listener); //5
}
public void actionPerformed (ActionEvent arg0) {
//6
temp=9*temp/5+32;
// 7
}
public static void main(String[] args) {
TempConvertGUI TC = new TempConvertGUI( );//8
//9
}
Thanks for all your help
Comment