Gui

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • outofmymind
    New Member
    • Oct 2006
    • 45

    Gui

    (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.

    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) {
    		-----------------------
    		-----------------------
    		}
    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
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by outofmymind
    (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.

    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) {
    		-----------------------
    		-----------------------
    		}
    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

    Code:
     import javax.swing.*;
    import java.awt.event.*; 
    public class TempConvertGUI extends JFrame implements ActionListener{
      JTextField TF;
      JButton B;
      JPanel P;
      JLabel L,result;
      float temp;
      public TempConvertGUI() {
       P = new JPanel();
       B =new JButton("convert");
       B.addActionListener(this);
       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);
       setVisible(true);
      }
      public void actionPerformed(ActionEvent arg0) {
       double val = Double.parseDouble(TF.getText());
       double temp=9 * val/5+32;
       result.setText(val+" degrees is"+temp +"F");
       this.setVisible(true);
      }
      public static void main(String[] args) {
       new TempConvertGUI();
      }
     }
    Compare with what you did and ask

    Comment

    Working...