diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..84c048a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/build/
diff --git a/nbproject/project.properties b/nbproject/project.properties
index 78a7076..8a57c79 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -71,7 +71,7 @@ jlink.additionalmodules=
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=GUIEsempio1
-main.class=guiesempio1.GUIEsempio1
+main.class=guiesempio1.PrimoEsempio
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
diff --git a/src/guiesempio1/PrimoEsempio.form b/src/guiesempio1/PrimoEsempio.form
index b606cd5..a329472 100644
--- a/src/guiesempio1/PrimoEsempio.form
+++ b/src/guiesempio1/PrimoEsempio.form
@@ -23,13 +23,103 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/guiesempio1/PrimoEsempio.java b/src/guiesempio1/PrimoEsempio.java
index 25cdb99..f7f581f 100644
--- a/src/guiesempio1/PrimoEsempio.java
+++ b/src/guiesempio1/PrimoEsempio.java
@@ -4,13 +4,16 @@
*/
package guiesempio1;
+import javax.swing.JOptionPane;
+
/**
*
* @author Verde
*/
public class PrimoEsempio extends javax.swing.JFrame {
-
- private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(PrimoEsempio.class.getName());
+
+ private static final java.util.logging.Logger logger = java.util.logging.Logger
+ .getLogger(PrimoEsempio.class.getName());
/**
* Creates new form PrimoEsempio
@@ -25,33 +28,124 @@ public class PrimoEsempio extends javax.swing.JFrame {
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
- // //GEN-BEGIN:initComponents
+ // //GEN-BEGIN:initComponents
private void initComponents() {
+ lblBinario = new javax.swing.JLabel();
+ txtDecimale = new javax.swing.JTextField();
+ btnUno = new javax.swing.JButton();
+ btnZero = new javax.swing.JButton();
+ btnConverti = new javax.swing.JButton();
+ lblDecimale = new javax.swing.JLabel();
+ txtBinario = new javax.swing.JTextField();
+
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ lblBinario.setText("Binario");
+ lblBinario.setToolTipText("Codifica del numero binario");
+
+ btnUno.setText("1");
+ btnUno.addActionListener(this::btnUnoActionPerformed);
+
+ btnZero.setText("0");
+ btnZero.addActionListener(this::btnZeroActionPerformed);
+
+ btnConverti.setText("Converti");
+ btnConverti.addActionListener(this::btnConvertiActionPerformed);
+
+ lblDecimale.setText("Decimale");
+ lblDecimale.setToolTipText("");
+
+ txtBinario.setEditable(false);
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
- );
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(25, 25, 25)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(lblDecimale)
+ .addGap(18, 18, 18)
+ .addComponent(txtDecimale, javax.swing.GroupLayout.PREFERRED_SIZE, 149,
+ javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(lblBinario)
+ .addGap(31, 31, 31)
+ .addGroup(layout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
+ false)
+ .addComponent(txtBinario)
+ .addComponent(btnConverti, javax.swing.GroupLayout.DEFAULT_SIZE,
+ 149, Short.MAX_VALUE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25,
+ Short.MAX_VALUE)
+ .addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 42,
+ javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(18, 18, 18)
+ .addComponent(btnUno, javax.swing.GroupLayout.PREFERRED_SIZE, 42,
+ javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(34, 34, 34)))));
layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
- );
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(36, 36, 36)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(lblBinario)
+ .addComponent(btnUno)
+ .addComponent(btnZero)
+ .addComponent(txtBinario, javax.swing.GroupLayout.PREFERRED_SIZE,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(18, 18, 18)
+ .addComponent(btnConverti)
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(txtDecimale, javax.swing.GroupLayout.PREFERRED_SIZE,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(lblDecimale))
+ .addContainerGap(41, Short.MAX_VALUE)));
pack();
}// //GEN-END:initComponents
+ private void btnZeroActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnZeroActionPerformed
+ txtBinario.setText(txtBinario.getText() + "0");
+ }// GEN-LAST:event_btnZeroActionPerformed
+
+ private void btnUnoActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnUnoActionPerformed
+ txtBinario.setText(txtBinario.getText() + "1");
+ }// GEN-LAST:event_btnUnoActionPerformed
+
+ private void btnConvertiActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnConvertiActionPerformed
+ String testoBinario = txtBinario.getText();
+ if (testoBinario == null || testoBinario.equals("")) {
+ JOptionPane.showMessageDialog(null, "Inserire un numero binario da convertire.");
+ } else {
+ try {
+ txtDecimale.setText(String.valueOf(Integer.parseInt(testoBinario, 2)));
+ } catch (NumberFormatException _) {
+ JOptionPane.showMessageDialog(null, "Inserire un numero binario valido da convertire.");
+ }
+ }
+ }// GEN-LAST:event_btnConvertiActionPerformed
+
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
- //
- /* 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
+ //
+ /*
+ * 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()) {
@@ -63,12 +157,19 @@ public class PrimoEsempio extends javax.swing.JFrame {
} catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
logger.log(java.util.logging.Level.SEVERE, null, ex);
}
- //
+ //
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> new PrimoEsempio().setVisible(true));
}
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton btnConverti;
+ private javax.swing.JButton btnUno;
+ private javax.swing.JButton btnZero;
+ private javax.swing.JLabel lblBinario;
+ private javax.swing.JLabel lblDecimale;
+ private javax.swing.JTextField txtBinario;
+ private javax.swing.JTextField txtDecimale;
// End of variables declaration//GEN-END:variables
}