Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Calc extends javax.swing.JFrame {
- private int op1 = 1;
- private int op2 = 1;
- private double num1;
- private double num2;
- public Calc() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- buttonGroup1 = new javax.swing.ButtonGroup();
- buttonGroup2 = new javax.swing.ButtonGroup();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jRadioButton1 = new javax.swing.JRadioButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jRadioButton3 = new javax.swing.JRadioButton();
- jRadioButton4 = new javax.swing.JRadioButton();
- jRadioButton5 = new javax.swing.JRadioButton();
- jRadioButton6 = new javax.swing.JRadioButton();
- jButton1 = new javax.swing.JButton();
- textField1 = new java.awt.TextField();
- textField2 = new java.awt.TextField();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel1.setText("Digite o valor da temperatura, sua unidade, e a unidade da temperatura convertida ");
- jLabel2.setText("Temperatura a");
- jLabel3.setText("Temperatura");
- jLabel4.setText("ser convertida");
- jLabel5.setText("convertida");
- buttonGroup1.add(jRadioButton1);
- jRadioButton1.setSelected(true);
- jRadioButton1.setText("Celcius");
- jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton1ActionPerformed(evt);
- }
- });
- buttonGroup1.add(jRadioButton2);
- jRadioButton2.setText("Fahrenhiet");
- jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton2ActionPerformed(evt);
- }
- });
- buttonGroup1.add(jRadioButton3);
- jRadioButton3.setText("Kelvin");
- jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton3ActionPerformed(evt);
- }
- });
- buttonGroup2.add(jRadioButton4);
- jRadioButton4.setSelected(true);
- jRadioButton4.setText("Celcius");
- jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton4ActionPerformed(evt);
- }
- });
- buttonGroup2.add(jRadioButton5);
- jRadioButton5.setText("Fahrenheit");
- jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton5ActionPerformed(evt);
- }
- });
- buttonGroup2.add(jRadioButton6);
- jRadioButton6.setText("Kelvin");
- jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton6ActionPerformed(evt);
- }
- });
- jButton1.setText("Calcular");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- textField1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textField1ActionPerformed(evt);
- }
- });
- textField2.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
- textField2.setEditable(false);
- textField2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- textField2ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel4)
- .addComponent(jLabel2))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel5)
- .addComponent(jLabel3)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(textField1, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
- .addComponent(textField2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(137, 137, 137)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton3)
- .addComponent(jRadioButton2)
- .addComponent(jRadioButton1))
- .addGap(33, 33, 33))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton6)
- .addComponent(jRadioButton5)
- .addComponent(jRadioButton4))
- .addContainerGap())))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(47, 47, 47))))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(61, 61, 61)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jRadioButton1)
- .addGap(8, 8, 8)
- .addComponent(jRadioButton2))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel4))))
- .addGroup(layout.createSequentialGroup()
- .addGap(59, 59, 59)
- .addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel3)
- .addGap(12, 12, 12)
- .addComponent(jLabel5)
- .addGap(61, 61, 61))
- .addGroup(layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton3)
- .addGap(34, 34, 34)
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jRadioButton4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(2, 2, 2)))
- .addComponent(jRadioButton5)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton6)
- .addGap(20, 20, 20))))
- );
- pack();
- }// </editor-fold>
- private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- op1 = 1;
- }
- private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- op1 = 2;
- }
- private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- op2 = 1;
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- calcula();
- }
- private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- op2 = 2;
- }
- private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {
- op2 = 3;
- }
- private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- op1 = 3;
- }
- private void textField1ActionPerformed(java.awt.event.ActionEvent evt) {
- num1 = Double.parseDouble(textField1.getText());
- }
- private void textField2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void calcula(){
- if (op1 == 1 && op2 == 1){
- num2 = num1;
- textField2.setText(""+num2);
- }
- else if (op1 == 1 && op2 == 2){
- num2 = (((num1*9)/5) + 32);
- textField2.setText(""+num2);
- }
- else if (op1 == 1 && op2 == 3){
- num2 = 273.15 + num1;
- textField2.setText(""+num2);
- }
- else if (op1 == 2 && op2 == 1){
- num2 = (((num1 - 32) * 5)/9);
- textField2.setText(""+num2);
- }
- else if (op1 == 2 && op2 == 2){
- num2 = num1;
- textField2.setText(""+num2);
- }
- else if (op1 == 2 && op2 == 3){
- num2 = (((num1 - 32) * 5)/9 + 273.15);
- textField2.setText(""+num2);
- }
- else if (op1 == 3 && op2 == 1){
- num2 = -273.15 + num1;
- textField2.setText(""+num2);
- }
- else if (op1 == 3 && op2 == 2){
- num2 = (((num1 - 273.15) * 9)/5 + 32);
- textField2.setText(""+num2);
- }
- else if (op1 == 3 && op2 == 3){
- num2 = num1;
- textField2.setText(""+num2);
- }
- }
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Calc().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.ButtonGroup buttonGroup1;
- private javax.swing.ButtonGroup buttonGroup2;
- private javax.swing.JButton jButton1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JRadioButton jRadioButton1;
- private javax.swing.JRadioButton jRadioButton2;
- private javax.swing.JRadioButton jRadioButton3;
- private javax.swing.JRadioButton jRadioButton4;
- private javax.swing.JRadioButton jRadioButton5;
- private javax.swing.JRadioButton jRadioButton6;
- private java.awt.TextField textField1;
- private java.awt.TextField textField2;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement