Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JLabel;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JOptionPane;
- public class TemperaturesFrame extends JFrame
- {
- private JLabel header;
- private JLabel Formulas;
- private JLabel FtoC;
- private JLabel CtoF;
- private JButton FCButton;
- private JButton CFButton;
- public TemperaturesFrame()
- {
- super( "Temperature Conversion" );
- setLayout( new FlowLayout() );
- header = new JLabel( "What are you converting?" );
- header.setToolTipText( "header" );
- add( header );
- FCButton = new JButton( "Fahrenheit to Celsius" );
- add( FCButton );
- CFButton = new JButton( "Celsius to Fahrenheit" );
- add( CFButton );
- Formulas = new JLabel( " - Formulas - " );
- Formulas.setToolTipText( "Formulas" );
- add( Formulas );
- FtoC = new JLabel( "Fahrenheit = Celsius * 5/9 + 32" );
- FtoC.setToolTipText( "FtoC" );
- add( FtoC );
- CtoF = new JLabel( "Celsius = (Fahrenheit - 32) * 5/9" );
- CtoF.setToolTipText( "CtoF" );
- add( CtoF );
- FCHandler handler1 = new FCHandler();
- FCButton.addActionListener( handler1 );
- CFHandler handler2 = new CFHandler();
- CFButton.addActionListener( handler2 );
- }
- private class FCHandler implements ActionListener
- {
- public void actionPerformed( ActionEvent event )
- {
- String fahrenheit =
- JOptionPane.showInputDialog( "Enter Fahrenheit" );
- int tempF = Integer.parseInt( fahrenheit );
- int Celsius = (tempF - 32) * 5/9;
- JOptionPane.showMessageDialog( null, "The celsius temperature is " +Celsius,
- "celsius", JOptionPane.PLAIN_MESSAGE );
- }
- }
- private class CFHandler implements ActionListener
- {
- public void actionPerformed( ActionEvent event )
- {
- String celsius =
- JOptionPane.showInputDialog( "Enter Celsius" );
- int tempC = Integer.parseInt( celsius );
- int Fahrenheit = tempC * 9 / 5 + 32;;
- JOptionPane.showMessageDialog( null, "The fahrenheit temperature is " +Fahrenheit,
- "Fahrenheit", JOptionPane.PLAIN_MESSAGE );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement