Logica
This commit is contained in:
@@ -26,12 +26,12 @@
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="32" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="txtNumeroConvertito" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblNumeroConvertito" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblBaseDestinataria" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="lblNumeroDaConvertire" max="32767" attributes="0"/>
|
||||
<Component id="txtNumeroDaConvertire" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="cmbBaseDestinataria" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="txtNueroConvertito" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="txtNumeroConvertito" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="24" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
@@ -49,9 +49,9 @@
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="cmbBaseDestinataria" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="txtNumeroConvertito" min="-2" pref="41" max="-2" attributes="0"/>
|
||||
<Component id="lblNumeroConvertito" min="-2" pref="41" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="txtNueroConvertito" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtNumeroConvertito" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="39" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
@@ -74,6 +74,9 @@
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cmbBaseDestinatariaItemStateChanged"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
@@ -83,12 +86,12 @@
|
||||
<Property name="text" type="java.lang.String" value="Base destinataria"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="txtNumeroConvertito">
|
||||
<Component class="javax.swing.JLabel" name="lblNumeroConvertito">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Numero convertito"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtNueroConvertito">
|
||||
<Component class="javax.swing.JTextField" name="txtNumeroConvertito">
|
||||
<Properties>
|
||||
<Property name="editable" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Verde
|
||||
*/
|
||||
public class GUIConvertiBasi extends javax.swing.JFrame {
|
||||
|
||||
|
||||
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(GUIConvertiBasi.class.getName());
|
||||
|
||||
/**
|
||||
@@ -30,8 +32,8 @@ public class GUIConvertiBasi extends javax.swing.JFrame {
|
||||
lblNumeroDaConvertire = new javax.swing.JLabel();
|
||||
cmbBaseDestinataria = new javax.swing.JComboBox<>();
|
||||
lblBaseDestinataria = new javax.swing.JLabel();
|
||||
txtNumeroConvertito = new javax.swing.JLabel();
|
||||
txtNueroConvertito = new javax.swing.JTextField();
|
||||
lblNumeroConvertito = new javax.swing.JLabel();
|
||||
txtNumeroConvertito = new javax.swing.JTextField();
|
||||
txtNumeroDaConvertire = new javax.swing.JTextField();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
@@ -39,12 +41,13 @@ public class GUIConvertiBasi extends javax.swing.JFrame {
|
||||
lblNumeroDaConvertire.setText("Numero da convertire");
|
||||
|
||||
cmbBaseDestinataria.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Binaria", "Ottale", "Esadecimale", "Vigesimale" }));
|
||||
cmbBaseDestinataria.addItemListener(this::cmbBaseDestinatariaItemStateChanged);
|
||||
|
||||
lblBaseDestinataria.setText("Base destinataria");
|
||||
|
||||
txtNumeroConvertito.setText("Numero convertito");
|
||||
lblNumeroConvertito.setText("Numero convertito");
|
||||
|
||||
txtNueroConvertito.setEditable(false);
|
||||
txtNumeroConvertito.setEditable(false);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
@@ -53,12 +56,12 @@ public class GUIConvertiBasi extends javax.swing.JFrame {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(32, 32, 32)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(txtNumeroConvertito)
|
||||
.addComponent(lblNumeroConvertito)
|
||||
.addComponent(lblBaseDestinataria)
|
||||
.addComponent(lblNumeroDaConvertire, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(txtNumeroDaConvertire)
|
||||
.addComponent(cmbBaseDestinataria, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(txtNueroConvertito))
|
||||
.addComponent(txtNumeroConvertito))
|
||||
.addContainerGap(24, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
@@ -73,15 +76,57 @@ public class GUIConvertiBasi extends javax.swing.JFrame {
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(cmbBaseDestinataria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(txtNumeroConvertito, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblNumeroConvertito, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(txtNueroConvertito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(txtNumeroConvertito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(39, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void cmbBaseDestinatariaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbBaseDestinatariaItemStateChanged
|
||||
// TODO add your handling code here:
|
||||
|
||||
String testo = txtNumeroDaConvertire.getText().trim();
|
||||
int numero = 0;
|
||||
String scelta;
|
||||
String risultato = null;
|
||||
|
||||
if (testo.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Inserire un numero.");
|
||||
txtNumeroDaConvertire.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
numero = Integer.parseInt(testo);
|
||||
} catch (NumberFormatException _) {
|
||||
JOptionPane.showMessageDialog(null, "Inserire un numero valido.");
|
||||
txtNumeroDaConvertire.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
scelta = cmbBaseDestinataria.getSelectedItem().toString();
|
||||
|
||||
switch (scelta) {
|
||||
case "Binaria":
|
||||
risultato = Integer.toBinaryString(numero);
|
||||
break;
|
||||
case "Ottale":
|
||||
risultato = Integer.toOctalString(numero);
|
||||
break;
|
||||
case "Esadecimale":
|
||||
risultato = Integer.toHexString(numero).toUpperCase();
|
||||
break;
|
||||
case "Vigesimale":
|
||||
risultato = Integer.toString(numero, 20).toUpperCase();
|
||||
break;
|
||||
}
|
||||
|
||||
txtNumeroConvertito.setText(risultato);
|
||||
}//GEN-LAST:event_cmbBaseDestinatariaItemStateChanged
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@@ -110,9 +155,9 @@ public class GUIConvertiBasi extends javax.swing.JFrame {
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JComboBox<String> cmbBaseDestinataria;
|
||||
private javax.swing.JLabel lblBaseDestinataria;
|
||||
private javax.swing.JLabel lblNumeroConvertito;
|
||||
private javax.swing.JLabel lblNumeroDaConvertire;
|
||||
private javax.swing.JTextField txtNueroConvertito;
|
||||
private javax.swing.JLabel txtNumeroConvertito;
|
||||
private javax.swing.JTextField txtNumeroConvertito;
|
||||
private javax.swing.JTextField txtNumeroDaConvertire;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user