JAVA GUI : برنامج لحساب المضروب
_______________________________________________
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
public class Factorial extends JFrame implements ActionListener{
JTextField number;
JButton press;
JLabel Result;
JPanel myPanel;
public Factorial(){
myPanel = new JPanel(new GridLayout(3 ,1, 20 ,0 ));
number = new JTextField(10);
myPanel=new JPanel();
number=new JTextField(10);
press=new JButton("press");
Result=new JLabel(" ");
press.addActionListener(this);
myPanel.add(number);
myPanel.add(press);
myPanel.add(Result);
this.add(myPanel);
}
public static void main(String[]args){
Factorial fact=new Factorial();
fact.setTitle("Factorial");
fact.setSize(300,100);
fact.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fact.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
if(event.getSource()==press){
int num = Integer.parseInt(number.getText()) ;
int fact=1;
for(int i=1;i<=num;i++)
fact*=i;
Result.setText(""+fact);
}
}
}
0 التعليقات: