Mientras intento sacar tiempo para recuperar todos los apuntes y ejercicios perdidos. Intentare mantenerme esta vez, mas al día con la clase. Ultimo trimestre, ultimo empujón. Animo a todos.
Como no se explicarme muy bien, he ido haciendo capturas, y os paso el código.
Código Completo:
*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package convertidor;
/**
*
* @author alumno
*/
public class Frame1 extends javax.swing.JFrame {
/**
* Creates new form Frame1
*/
public Frame1() {
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() {
MessageBox = new javax.swing.JDialog();
jLabel4 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
MessageBox2 = new javax.swing.JDialog();
jLabel5 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtEuros = new javax.swing.JTextField();
txtDolares = new javax.swing.JTextField();
btnConvertir = new javax.swing.JButton();
btnConvertir2 = new javax.swing.JButton();
jLabel4.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
jLabel4.setText("La caja de textos euros esta vacia");
jButton1.setText("Aceptar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout MessageBoxLayout = new javax.swing.GroupLayout(MessageBox.getContentPane());
MessageBox.getContentPane().setLayout(MessageBoxLayout);
MessageBoxLayout.setHorizontalGroup(
MessageBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(MessageBoxLayout.createSequentialGroup()
.addGroup(MessageBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(MessageBoxLayout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel4))
.addGroup(MessageBoxLayout.createSequentialGroup()
.addGap(100, 100, 100)
.addComponent(jButton1)))
.addContainerGap(31, Short.MAX_VALUE))
);
MessageBoxLayout.setVerticalGroup(
MessageBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(MessageBoxLayout.createSequentialGroup()
.addGap(35, 35, 35)
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(20, Short.MAX_VALUE))
);
jLabel5.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N
jLabel5.setText("Las casillas estan vacías");
jButton2.setText("Aceptar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout MessageBox2Layout = new javax.swing.GroupLayout(MessageBox2.getContentPane());
MessageBox2.getContentPane().setLayout(MessageBox2Layout);
MessageBox2Layout.setHorizontalGroup(
MessageBox2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(MessageBox2Layout.createSequentialGroup()
.addGroup(MessageBox2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(MessageBox2Layout.createSequentialGroup()
.addGap(45, 45, 45)
.addComponent(jLabel5))
.addGroup(MessageBox2Layout.createSequentialGroup()
.addGap(89, 89, 89)
.addComponent(jButton2)))
.addContainerGap(45, Short.MAX_VALUE))
);
MessageBox2Layout.setVerticalGroup(
MessageBox2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(MessageBox2Layout.createSequentialGroup()
.addContainerGap(44, Short.MAX_VALUE)
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(jButton2)
.addGap(36, 36, 36))
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Calculadora Conversora");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(51, 0, 153));
jLabel1.setText("Calculadora");
jLabel2.setText("Euros");
jLabel3.setText("Dólares");
txtEuros.setBackground(new java.awt.Color(255, 204, 255));
txtDolares.setBackground(new java.awt.Color(204, 255, 204));
btnConvertir.setText("Convertir");
btnConvertir.setToolTipText("Convierte de Euros a Dólares");
btnConvertir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnConvertirActionPerformed(evt);
}
});
btnConvertir2.setText("Convertir completo");
btnConvertir2.setToolTipText("Convierte en ambos sentidos");
btnConvertir2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnConvertir2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtEuros, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(59, 59, 59)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtDolares, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(btnConvertir))))
.addContainerGap(31, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnConvertir2)
.addGap(183, 183, 183))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel1)
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtEuros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtDolares, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addComponent(btnConvertir)))
.addGap(18, 18, 18)
.addComponent(btnConvertir2)
.addContainerGap(25, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
//boton convertir todo
private void btnConvertir2ActionPerformed(java.awt.event.ActionEvent evt) {
if(txtEuros.getText().compareTo("")==0 && txtDolares.getText().compareTo("")==0)
{
//arrojamos un mensaje
MessageBox2.setVisible(true);
MessageBox2.setSize(250,150);
}
else if(txtEuros.getText().compareTo("")!=0)
{
double euros=Double.parseDouble(txtEuros.getText());
double dolares=euros*1.3194;
txtDolares.setText(Double.toString(dolares));
}
else
{
double dolares=Double.parseDouble(txtDolares.getText());
double euros=dolares/1.3194;
txtEuros.setText(Double.toString(euros));
}
}
//boton convertir
private void btnConvertirActionPerformed(java.awt.event.ActionEvent evt) {
if(txtEuros.getText().compareTo("")==0)
{
//arrojamos un mensaje
MessageBox.setVisible(true);
MessageBox.setSize(300,150);
}
else
{
double euros=Double.parseDouble(txtEuros.getText());
double dolares=euros*1.3194;
txtDolares.setText(Double.toString(dolares));
}
}
//Boton aceptar del messageBox
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MessageBox.dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MessageBox2.dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JDialog MessageBox;
private javax.swing.JDialog MessageBox2;
private javax.swing.JButton btnConvertir;
private javax.swing.JButton btnConvertir2;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
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.JTextField txtDolares;
private javax.swing.JTextField txtEuros;
// End of variables declaration
}
0 comentarios:
Publicar un comentario