Ai um exemplo so implementar a função de converter
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* GUI.java
*
* Created on 11/03/2010, 16:52:30
*/
package javaapplication8;
import javax.swing.JOptionPane;
/**
*
* @author suporte
*/
public class GUI extends javax.swing.JFrame {
/** Creates new form GUI */
public GUI() {
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() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
tipo1 = new javax.swing.JComboBox();
tipo2 = new javax.swing.JComboBox();
valor = new javax.swing.JTextField();
b_resultado = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
txt_tipo1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txt_tipo2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txt_result = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
tipo1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Decimal", "Octal", "Hexadecimal", "Binario" }));
tipo1.setSelectedIndex(2);
tipo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Decimal", "Octal", "Hexadecimal", "Binario" }));
b_resultado.setText("Resultado");
b_resultado.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_resultadoActionPerformed(evt);
}
});
jLabel1.setText("Converter ");
txt_tipo1.setForeground(java.awt.Color.red);
org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tipo1, org.jdesktop.beansbinding.ELProperty.create("${selectedItem}"), txt_tipo1, org.jdesktop.beansbinding.BeanProperty.create("text"));
bindingGroup.addBinding(binding);
jLabel2.setText("para");
txt_tipo2.setForeground(java.awt.Color.red);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tipo2, org.jdesktop.beansbinding.ELProperty.create("${selectedItem}"), txt_tipo2, org.jdesktop.beansbinding.BeanProperty.create("text"));
bindingGroup.addBinding(binding);
jLabel3.setText("=");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(tipo1, javax.swing.GroupLayout.Alignment.LEADING, 0, 306, Short.MAX_VALUE)
.addComponent(tipo2, javax.swing.GroupLayout.Alignment.LEADING, 0, 306, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_tipo1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_tipo2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt_result, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(valor, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(b_resultado)))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txt_tipo1, txt_tipo2});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(tipo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tipo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(valor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(b_resultado))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txt_tipo1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(txt_tipo2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(txt_result, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(21, Short.MAX_VALUE))
);
bindingGroup.bind();
pack();
}// </editor-fold>
private void b_resultadoActionPerformed(java.awt.event.ActionEvent evt) {
if (tipo1.getSelectedIndex() != tipo2.getSelectedIndex()) {
Object obj = valor.getText();
//Logica de converção
Object convertido = null;
txt_result.setText(convertido.toString());
} else {
JOptionPane.showMessageDialog(this, "Tipos devem ser diferentes");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton b_resultado;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JComboBox tipo1;
private javax.swing.JComboBox tipo2;
private javax.swing.JLabel txt_result;
private javax.swing.JLabel txt_tipo1;
private javax.swing.JLabel txt_tipo2;
private javax.swing.JTextField valor;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration
}