2007/09/21

Java: Formulario de clase bisiesto

Este es el formulario de la clase que calcula el año bisiesto, el siguiente es el archivo .java se llama gui.java:



/*
* gui.java
*
* Created on 21 de septiembre de 2007, 15:48
*/

package bisiesto;

/**
*
* @author dalfa
*/
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.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jButton1 = new javax.swing.JButton();
lbl1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txt1 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setLabel("Calcular");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel2.setText("Introduzca el a\u00f1o");

jButton2.setLabel("Salir");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setLabel("Limpiar");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbl1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txt1, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txt1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(25, 25, 25)
.addComponent(lbl1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton1))
.addContainerGap(40, Short.MAX_VALUE))
);
pack();
}//
//GEN-END:initComponents

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO: Agrege su codigo aqui:
txt1.setText("");
lbl1.setText("");
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO: Agrege su codigo aqui:
System.exit(0);
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO: Agrege su codigo aqui:

bisiesto b = new bisiesto ();
b.ano=Integer.valueOf(txt1.getText());
lbl1.setText(b.calcular(b.ano));

}//GEN-LAST:event_jButton1ActionPerformed

/**
* @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);
}
});
}

// Declaración de varibales -no modificar//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lbl1;
private javax.swing.JTextField txt1;
// Fin de declaración de variables//GEN-END:variables

}



Y aqui esta el archivo .form del formulario se llama gui.form:



<?xml version="1.0" encoding="UTF-8" ?>



<form version="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">

<properties>

<property name="defaultCloseOperation" type="int" value="3">

</properties>

<syntheticproperties>

<syntheticproperty name="formSizePolicy" type="int" value="1">

</syntheticproperties>

<auxvalues>

<auxvalue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false">

<auxvalue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1">

<auxvalue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0">

<auxvalue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false">

<auxvalue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2">

</auxvalues>



<layout>

<dimensionlayout dim="0">

<group type="103" groupalignment="0" attributes="0">

<group type="102" attributes="0">

<group type="103" groupalignment="0" attributes="0">

<group type="102" attributes="0">

<emptyspace max="-2" attributes="0">

<group type="103" groupalignment="0" attributes="0">

<component id="lbl1" alignment="0" min="-2" pref="117" max="-2" attributes="0">

<group type="102" alignment="0" attributes="0">

<component id="jLabel2" min="-2" max="-2" attributes="0">

<emptyspace max="-2" attributes="0">

<component id="txt1" pref="126" max="32767" attributes="1">

<emptyspace max="-2" attributes="0">

</group>

</group>

<emptyspace min="-2" max="-2" attributes="0">

</group>

<group type="102" alignment="1" attributes="0">

<emptyspace max="-2" attributes="0">

<component id="jButton1" min="-2" max="-2" attributes="0">

<emptyspace max="-2" attributes="0">

<component id="jButton3" min="-2" max="-2" attributes="0">

<emptyspace max="-2" attributes="0">

<component id="jButton2" min="-2" pref="69" max="-2" attributes="0">

</group>

</group>

<emptyspace max="-2" attributes="0">

</group>

</group>

</dimensionlayout>

<dimensionlayout dim="1">

<group type="103" groupalignment="0" attributes="0">

<group type="102" alignment="0" attributes="0">

<emptyspace min="-2" pref="28" max="-2" attributes="0">

<group type="103" groupalignment="3" attributes="0">

<component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0">

<component id="txt1" alignment="3" min="-2" max="-2" attributes="0">

</group>

<emptyspace min="-2" pref="25" max="-2" attributes="0">

<component id="lbl1" min="-2" pref="18" max="-2" attributes="0">

<emptyspace max="-2" attributes="0">

<group type="103" groupalignment="3" attributes="0">

<component id="jButton2" alignment="3" min="-2" max="-2" attributes="0">

<component id="jButton3" alignment="3" min="-2" max="-2" attributes="0">

<component id="jButton1" alignment="3" min="-2" max="-2" attributes="0">

</group>

<emptyspace pref="40" max="32767" attributes="0">

</group>

</group>

</dimensionlayout>

</layout>

<subcomponents>

<component class="javax.swing.JButton" name="jButton1">

<properties>

<property name="label" type="java.lang.String" value="Calcular">

</properties>

<events>

<eventhandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed">

</events>

</component>

<component class="javax.swing.JLabel" name="lbl1">

</component>

<component class="javax.swing.JLabel" name="jLabel2">

<properties>

<property name="text" type="java.lang.String" value="Introduzca el año">

</properties>

</component>

<component class="javax.swing.JTextField" name="txt1">

</component>

<component class="javax.swing.JButton" name="jButton2">

<properties>

<property name="label" type="java.lang.String" value="Salir">

</properties>

<events>

<eventhandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed">

</events>

</component>

<component class="javax.swing.JButton" name="jButton3">

<properties>

<property name="label" type="java.lang.String" value="Limpiar">

</properties>

<events>

<eventhandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton3ActionPerformed">

</events>

</component>

</subcomponents>

</form>



2 comentarios:

Juliuss dijo...

Interesante, hasta le pusiste advertencia de uso. Consulta; que editor usas?.

Dalfa dijo...

@Juliuss, esto lo he hecho en NetBEANS pero me han afamado mucho eclipse pero no lo he probado.