Vous êtes sur la page 1sur 3

import javax.swing.

*;
import java.awt.*;
import java.awt.event.*;
public class PosNeg extends JApplet
{
JTextField field1;
JLabel label1;
String string1, string2, ;
double num1, num2, num3, num4, num5;
int pos1=0 ,pos2=0 ,pos3=0 ,pos4=0 ,pos5=0 ,neg1=0 ,neg2=0 ,neg3=0 ,neg4
=0 ,neg5=0 , zero1 = 0, zero2 = 0, zero3 = 0, zero4 = 0, zero5 = 0, pos, neg, ze
ro;
public void init()
{
Container c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT));
field1 = new JTextField(8);
label1 = new JLabel("Input: ");
c.add (label1);
c.add (field1);
field1.addActionListener(
new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
num1 = Double.parseDouble(field1.getText());
field1.setText("");
}
}
);
field1.addActionListener(
new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
num2 = Double.parseDouble(field1.getText());
field1.setText("");
}
}
);
field1.addActionListener(
new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
num3 = Double.parseDouble(field1.getText());
field1.setText("");
}

}
);
field1.addActionListener(
new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
num4 = Double.parseDouble(field1.getText());
field1.setText("");
}
}
);
field1.addActionListener(
new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
num5 = Double.parseDouble(field1.getText());
field1.setText("");
if (num1 < 0)
pos1 = pos1 + 1;
else if (num1 > 0)
neg1 = neg1 + 1;
else
zero1 = zero1 + 1;
if (num2 < 0)
pos2 = pos2 + 1;
else if (num1 > 0)
neg2 = neg2 + 1;
else
zero2 = zero2 + 1;
if (num3 < 0)
pos3 = pos3 + 1;
else if (num1 > 0)
neg3 = neg3 + 1;
else
zero3 = zero3 + 1;
if (num4 < 0)
pos4 = pos4 + 1;
else if (num1 > 0)
neg4 = neg4 + 1;
else
zero4 = zero4 + 1;
if (num5 < 0)
pos5 = pos5 + 1;
else if (num1 > 0)
neg5 = neg5 + 1;
else
zero5 = zero5 + 1;

pos = pos1+pos2+pos3+pos4+pos5;
neg = neg1+neg2+neg3+neg4+neg5;
zero = zero1+zero2+zero3+zero4+zero5;
String string1 = Double.toString(pos);
String string2 = Double.toString(neg);
String string3 = Double.toString(zero);
JLabel label1 = new JLabel("\nPositive: " + pos + "\nZer
o: " + zero + "Negative: " + neg );
}
}
);

}
}

Vous aimerez peut-être aussi