|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: |
// Temperature Conversion Applet
import java.applet.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class calculator
extends Applet
implements ActionListener
{
private TextField tfInput, tfResult;
private Button btF2C, btC2F,btF2K, btK2F, btC2K, btK2C;
private final String F2C = new String("Fahrenheit to Celsius");
private final String C2F = new String("Celsius to Fahrenheit");
private final String F2K = new String("Fahrenheit to Kelvin");
private final String K2F = new String("Kelvin to Fahrenheit");
private final String C2K = new String("Celsius to Kelvin");
private final String K2C = new String("Kelvin to Celsius");
//initialize user interface
public void init()
{
//set layout and foreground colors
setLayout(new BorderLayout());
setBackground(Color.white);
setFont(new Font("Times New Roman", Font.PLAIN, 14));
//create text fields
tfInput = new TextField(6);
tfResult = new TextField(6);
//set result field read only
tfResult.setEditable(false);
//create buttons
btF2C = new Button(F2C);
btC2F = new Button(C2F);
btF2K = new Button(F2K);
btK2F = new Button(K2F);
btC2K = new Button(C2K);
btK2C = new Button(K2C);
//register listeners
btF2C.addActionListener(this);
btC2F.addActionListener(this);
btF2K.addActionListener(this);
btK2F.addActionListener(this);
btC2K.addActionListener(this);
btK2C.addActionListener(this);
//create 3 panels
Panel p1 = new Panel();
p1.add(new Label(
"Enter a temperature and select conversion type:"));
p1.add(tfInput);
Panel p2 = new Panel();
p2.add(new Label("Result:"));
p2.add(tfResult);
Panel p3 = new Panel();
p3.add(btF2C);
p3.add(btC2F);
p3.add(btF2K);
p3.add(btK2F);
p3.add(btC2K);
p3.add(btK2C);
// add panels to frame
add(BorderLayout.NORTH, p1);
add(BorderLayout.CENTER, p2);
add(BorderLayout.SOUTH, p3);
}
//event handler for buttons
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
double t1, t2,t3,t4,t5,t6, t7;
// get input temp
t1=(Double.valueOf(tfInput.getText())).doubleValue();
// compute result
//F2C = (((t1 - 32) / 9) * 5);
t2=actionCommand.equals(F2C) ? 5*(t1-32)/9 : 9*t1/5 + 32 ;
t3=actionCommand.equals(F2K) ? (5*(t1-32)/9+273.15) : 9*t1/5 +305.15;
// display result
tfResult.setText(String.valueOf(t2));
}
}
***************************************
<html>
<applet code = "calculator.class" width = "1000" height = "300">
</applet>
</html>
|
Advertisement
| Hall of Fame |