lunes, 23 de abril de 2007

determinar si un numero es positivo, negativo o cero

import com.sun.org.apache.bcel.internal.verifier.statics.DOUBLE_Upper;
/*
* UsoIf.java
*
* Created on 17 de abril de 2007, 07:15 PM
*/

/**
*
* @author ALUMNO
*/
public class UsoIf extends javax.swing.JFrame {

/** Creates new form UsoIf */
public UsoIf() {
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() {
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jLabel1 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jTextPane2 = new javax.swing.JTextPane();
jButton1 = new javax.swing.JButton();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setViewportView(jTextPane1);

jLabel1.setText("Numero");

jTextPane2.setEditable(false);
jScrollPane2.setViewportView(jTextPane2);

jButton1.setText("Evalua");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
});

org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(28, 28, 28)
.add(jLabel1)
.add(22, 22, 22)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane2,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 189,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jScrollPane1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 111,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(layout.createSequentialGroup()
.add(161, 161, 161)
.add(jButton1)))
.addContainerGap(124, Short.MAX_VALUE))
);
layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(31, 31, 31)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.add(64, 64, 64)
.add(jScrollPane2,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(57, 57, 57)
.add(jButton1)
.addContainerGap(77, Short.MAX_VALUE))
);
pack();
}//
//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt)
{//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
double n;

n = Double.parseDouble(jTextPane1.getText());

if(n>0)
jTextPane2.setText("Numero Positivo");
else if(n<0)
jTextPane2.setText("Numero Negativo");
else
jTextPane2.setText("Numero es cero");

}//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 UsoIf().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextPane jTextPane1;
private javax.swing.JTextPane jTextPane2;
// End of variables declaration//GEN-END:variables

No hay comentarios: