Mon May 26, 2008 12:22 am
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
*
* @author SAMI
*/
public class mApplet extends JApplet implements ChangeListener{
/** Creates a new instance of Main */
private JSlider slider=new JSlider(JSlider.HORIZONTAL,0,100,30);
private JLabel CLable=new JLabel("Celsius :");
private JLabel FLable=new JLabel("Fahrenheit :");
private JLabel CLableValue=new JLabel("");
private JLabel FLableValue=new JLabel("");
private Container cp;
private float CDegree;
private float FrDegree;
public mApplet() {
cp=getContentPane();
slider.addChangeListener(this);
CDegree=slider.getValue();
getFahrenheit();
updateTexts();
cp.setLayout(new GridLayout(3,3));
cp.add(CLable);
cp.add(CLableValue);
cp.add(FLable);
cp.add(FLableValue);
cp.add(slider);
}
public void init() {
}
public void start() {
}
public void stop() {
}
public void destroy() {
}
public void stateChanged(ChangeEvent e) {
CDegree=slider.getValue();
getFahrenheit();
updateTexts();
}
public void getFahrenheit() {
FrDegree=(float)(CDegree*(float)9/5) + 32;
}
public void updateTexts()
{
CLableValue.setText(Float.toString(CDegree));
FLableValue.setText(Float.toString(FrDegree));
}
}
Mon Jan 21, 2013 12:43 am
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.