Prima GUI funziona (fatto con NetBeans)

This commit is contained in:
La Programmatrice Verde
2026-01-22 12:03:59 +01:00
parent e1e5d7f5c1
commit 6ed2f1b477
4 changed files with 208 additions and 16 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build/

View File

@@ -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

View File

@@ -23,13 +23,103 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="25" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="lblDecimale" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="txtDecimale" min="-2" pref="149" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblBinario" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="31" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="txtBinario" max="32767" attributes="0"/>
<Component id="btnConverti" pref="149" max="32767" attributes="0"/>
</Group>
<EmptySpace pref="25" max="32767" attributes="0"/>
<Component id="btnZero" min="-2" pref="42" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnUno" min="-2" pref="42" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="34" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblBinario" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnUno" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnZero" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtBinario" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnConverti" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtDecimale" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lblDecimale" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="41" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblBinario">
<Properties>
<Property name="text" type="java.lang.String" value="Binario"/>
<Property name="toolTipText" type="java.lang.String" value="Codifica del numero binario"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtDecimale">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtDecimaleActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnUno">
<Properties>
<Property name="text" type="java.lang.String" value="1"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnUnoActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnZero">
<Properties>
<Property name="text" type="java.lang.String" value="0"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnZeroActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnConverti">
<Properties>
<Property name="text" type="java.lang.String" value="Converti"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnConvertiActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblDecimale">
<Properties>
<Property name="text" type="java.lang.String" value="Decimale"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtBinario">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="txtBinarioActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@@ -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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated
// Code">//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();
}// </editor-fold>//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 */
//<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
// <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()) {
@@ -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);
}
//</editor-fold>
// </editor-fold>
/* 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
}