
-----------------------------------
Agreyscape
Tue Jan 12, 2010 2:10 pm

What is wrong with my program?
-----------------------------------
/*Computer Science summative
 * Mr. Paterson
 * January 11, 2010
 *Agrey the rat amd Raagu the hippo */

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Scanner;
public class ClassSummative // Names package
{
  public static void main (String

Everything works fine but the temp converter. When I enter a number and click convert it doesn't do it. Please help.[/quote]

-----------------------------------
Barbarrosa
Tue Jan 12, 2010 4:17 pm

Re: What is wrong with my program?
-----------------------------------
Welcome to Computer Science Canada.

First, a few recommendations about code comments:

Don't comment every single line unless it's necessary or particularly helpful.
Over-commenting is never a replacement for writing helpful comments.
Try commenting at the top about the general purpose of the program, and then describe each different section. Apply this to the code here, too.


Also, please use "code" or "syntax" tags around code in your posts. For example:  ... 
convButton = new JButton("Convert to fahrenheit");
convButton.addActionListener(new AvgListener());//look here
contentPane.add(convButton);

stat = new JLabel(" F");
stat.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
contentPane.add(stat);

frame.setContentPane(contentPane);

frame.pack();
frame.setVisible(true);


class AvgListener implements ActionListener {//look here
public void actionPerformed(ActionEvent event) {
double avgTemp;
String t1 = temp1.getText();

avgTemp = (double)9/(double)5*(Double.parseDouble(t1)) + 32;
stat.setText(Double.toString(avgTemp));
} 


-----------------------------------
Agreyscape
Tue Jan 12, 2010 5:52 pm

Re: What is wrong with my program?
-----------------------------------
Ok so I put the class AvgListener first and now when I run it there is no convert button its pretty much a dead box.


        class AvgListener implements ActionListener {//look here
          public void actionPerformed(ActionEvent event) {
            double avgTemp;
            String t1 = temp1.getText();
            
            convButton.addActionListener(new AvgListener());//look here
            contentPane.add(convButton);
            avgTemp = (double)9/(double)5*(Double.parseDouble(t1)) + 32;
            stat.setText(Double.toString(avgTemp));
          } 

