Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)KonversiGuiNew.java
- *
- * KonversiGuiNew application
- *
- * @author
- * @version 1.00 2017/10/2
- */
- public class KonversiGuiNew {
- public static void main(String[] args) {
- JavaGui obj = new JavaGui();
- obj.setVisible(true);
- }
- }
- /**
- * Class JavaGui
- */
- import javax.swing.*;
- import java.awt.event.*;
- import java.awt.*;
- class JavaGui extends JFrame {
- JPanel panel = new JPanel();
- JLabel label1 = new JLabel("Celcius");
- JLabel label2 = new JLabel("Reamur");
- JLabel label3 = new JLabel("Farenheit");
- JLabel label4 = new JLabel("Reamur");
- JTextField celcius = new JTextField();
- JTextField reamur = new JTextField();
- JTextField farenheit = new JTextField();
- //JButton btnConvert = new JButton("Convert");
- JButton btnCelciusToRToF = new JButton("Convert");
- JButton btnReamurToCToF = new JButton("Convert");
- JButton btnFarenheitToCToR = new JButton("Convert");
- JButton btnClear = new JButton("Clear");
- public JavaGui(){
- panel.setLayout(null);
- add(panel);
- label1.setBounds(15, 20, 80, 25);
- label2.setBounds(15, 50, 80, 25);
- label3.setBounds(15, 80, 80, 25);
- celcius.setBounds(120, 20, 100, 25);
- reamur.setBounds(120, 50, 100, 25);
- farenheit.setBounds(120, 80, 100, 25);
- //btnConvert.setBounds(15, 120, 90, 25);
- btnCelciusToRToF.setBounds(250, 20, 90, 25);
- btnReamurToCToF.setBounds(250, 50, 90, 25);
- btnFarenheitToCToR.setBounds(250, 80, 90, 25);
- btnClear.setBounds(100, 120, 90, 25);
- panel.add(label1);
- panel.add(label2);
- panel.add(label3);
- panel.add(celcius);
- panel.add(reamur);
- panel.add(farenheit);
- //panel.add(btnConvert);
- panel.add(btnCelciusToRToF);
- panel.add(btnReamurToCToF);
- panel.add(btnFarenheitToCToR);
- panel.add(btnClear);
- setTitle("Konversi Suhu");
- setBounds(500, 200, 400, 200);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- /**btnConvert.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- int tampung = 0, tampung1 = 1, tampung2 = 2;
- if(celciusToRToF(tampung) == 0){
- celciusToRToF(tampung);
- tampung2 = 3;
- }
- if(reamurToCToF(tampung1) == 1){
- reamurToCToF(tampung1);
- tampung = 1;
- }
- if(farenheitToCToR(tampung2) == 2){
- farenheitToCToR(tampung2);
- tampung1 = 2;
- }
- }
- });**/
- btnCelciusToRToF.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- celciusToRToF();
- }
- });
- btnReamurToCToF.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- reamurToCToF();
- }
- });
- btnFarenheitToCToR.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- farenheitToCToR();
- }
- });
- btnClear.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- clearData();
- }
- });
- }
- float hasil;
- final float suhuTampung = 4, suhuTampung2 = 9;
- public float celciusToRToF(){
- //Celcius To Reamur
- float celciusIsi = Float.parseFloat(celcius.getText());
- hasil = suhuTampung / 5 * celciusIsi;
- reamur.setText(Float.toString(hasil));
- //Celcius To Farenheit
- hasil = (suhuTampung2 / 5 * celciusIsi) + 32;
- farenheit.setText(Float.toString(hasil));
- return hasil;
- }
- public float reamurToCToF(){
- //Reamur To Celcius
- float reamurIsi = Float.parseFloat(reamur.getText());
- hasil = 5 / suhuTampung * reamurIsi;
- celcius.setText(Float.toString(hasil));
- //Reamur To Farenheit
- hasil = (suhuTampung2 / suhuTampung * reamurIsi) + 32;
- farenheit.setText(Float.toString(hasil));
- return hasil;
- }
- public float farenheitToCToR(){
- //Farenheit To Celcius
- float farenheitIsi = Float.parseFloat(farenheit.getText());
- hasil = 5 / suhuTampung2 * (farenheitIsi - 32);
- celcius.setText(Float.toString(hasil));
- //Farenheit To Reamur
- hasil = suhuTampung / suhuTampung2 * (farenheitIsi - 32);
- reamur.setText(Float.toString(hasil));
- return hasil;
- }
- public void clearData(){
- celcius.setText("");
- reamur.setText("");
- farenheit.setText("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment