By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,558 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,558 IT Pros & Developers. It's quick & easy.

Gui

P: 45
(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.

Expand|Select|Wrap|Line Numbers
  1. -----------
  2. ---------------
  3. public class TempConvertGUI extends JFrame implements                     ActionListener{
  4.         JTextField TF;
  5.         JButton B;
  6.         JPanel P;
  7.         JLabel L,result;
  8.         float temp;
  9.         public TempConvertGUI(){
  10.         ------------------------------
  11.         L=new JLabel("Enter Temp in Celsius");
  12.         TF=new JTextField(5);
  13.         ------------------------------        
  14.         result=new JLabel("  ");
  15.         -----------------
  16.         P.add(L);
  17.         P.add(TF);
  18.         P.add(B);
  19.         P.add(result);
  20.         this.getContentPane().add(P);
  21.         ------------------------------
  22.         this.setSize(300,300);
  23.         -------------
  24.         }
  25.         public void actionPerformed(ActionEvent arg0) {
  26.         ---------------
  27.         temp=9*temp/5+32;
  28.         --------------------        
  29.         }
  30.         public static void main(String[] args) {
  31.         -----------------------
  32.         -----------------------
  33.         }
  34.  
  35.  
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("convert"); //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.getContentPane().add(P);
ActionListener listener = new ClickListener(); //4
this.setSize(300,300);
B.addActionListener(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
Jan 8 '07 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
(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.

Expand|Select|Wrap|Line Numbers
  1. -----------
  2. ---------------
  3. public class TempConvertGUI extends JFrame implements                     ActionListener{
  4.         JTextField TF;
  5.         JButton B;
  6.         JPanel P;
  7.         JLabel L,result;
  8.         float temp;
  9.         public TempConvertGUI(){
  10.         ------------------------------
  11.         L=new JLabel("Enter Temp in Celsius");
  12.         TF=new JTextField(5);
  13.         ------------------------------        
  14.         result=new JLabel(" ");
  15.         -----------------
  16.         P.add(L);
  17.         P.add(TF);
  18.         P.add(B);
  19.         P.add(result);
  20.         this.getContentPane().add(P);
  21.         ------------------------------
  22.         this.setSize(300,300);
  23.         -------------
  24.         }
  25.         public void actionPerformed(ActionEvent arg0) {
  26.         ---------------
  27.         temp=9*temp/5+32;
  28.         --------------------        
  29.         }
  30.         public static void main(String[] args) {
  31.         -----------------------
  32.         -----------------------
  33.         }
  34.  
  35.  
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("convert"); //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.getContentPane().add(P);
ActionListener listener = new ClickListener(); //4
this.setSize(300,300);
B.addActionListener(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

Expand|Select|Wrap|Line Numbers
  1.  import javax.swing.*;
  2. import java.awt.event.*; 
  3. public class TempConvertGUI extends JFrame implements ActionListener{
  4.   JTextField TF;
  5.   JButton B;
  6.   JPanel P;
  7.   JLabel L,result;
  8.   float temp;
  9.   public TempConvertGUI() {
  10.    P = new JPanel();
  11.    B =new JButton("convert");
  12.    B.addActionListener(this);
  13.    L=new JLabel("Enter Temp in Celsius");
  14.    TF=new JTextField(5);
  15.    result=new JLabel("  ");
  16.    P.add(L);
  17.    P.add(TF);
  18.    P.add(B);
  19.    P.add(result);
  20.    this.getContentPane().add(P);
  21.    this.setSize(300,300);
  22.    setVisible(true);
  23.   }
  24.   public void actionPerformed(ActionEvent arg0) {
  25.    double val = Double.parseDouble(TF.getText());
  26.    double temp=9 * val/5+32;
  27.    result.setText(val+" degrees is"+temp +"F");
  28.    this.setVisible(true);
  29.   }
  30.   public static void main(String[] args) {
  31.    new TempConvertGUI();
  32.   }
  33.  }
  34.  
  35.  
Compare with what you did and ask
Jan 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.