Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to Use ActionListener for User pressing ENTER in JTextField

$
0
0
This is my output constructor where all my calculations are done. I am working on trying to let user Press ENTER in JTextField labeled inputbox and I am stuck. Can someone please give me some guidance or direction here?


public void outputConvertedTemp()
	{
		
		//reads buttons selected to determine output
		double temp;
		double newtemp = 0;
		temp = Double.parseDouble(inputbox.getText());
		
		if (CelsiusIn.isSelected() & KelvinOut.isSelected())
				newtemp = (temp + 273.15);//c to k
		else if (FahrenheitIn.isSelected() & KelvinOut.isSelected())
				newtemp = ((temp + 459.67) * 0.556);//f to k
		else if (KelvinIn.isSelected() & FahrenheitOut.isSelected())
			newtemp = (((temp * 1.8) - 459.67));//k to f
		else if (CelsiusIn.isSelected() & FahrenheitOut.isSelected())
			newtemp = (((1.8) * temp) + 32);//c to f
		else if (FahrenheitIn.isSelected() & CelsiusOut.isSelected())
			newtemp = ((.556) * (temp - 32));//f to c
		else if (KelvinIn.isSelected() & CelsiusOut.isSelected())
			newtemp = (temp - 273.15);//k to c
		//the following are to ensure that the output stays what it should be
		else if (CelsiusIn.isSelected() & CelsiusOut.isSelected())
			newtemp = temp;
		else if (FahrenheitIn.isSelected() & FahrenheitOut.isSelected())
			newtemp = temp;
		else if (KelvinIn.isSelected() & KelvinOut.isSelected())
			newtemp = temp;
		String degree = "" + (char)186;
		outputbox.setText("" + two.format(newtemp) + degree);
	}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>