لعبة المزرعة السعيدة لعبة الفراخ

جافا : GUI من ابداعات الطالبة الاء غانم .. برنامج للتحويل من النظام العشري الى الثنائي

import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;

public class MyDecimalToBinary extends JFrame implements ActionListener{
JPanel myPanel ;
JTextField number ; 
JLabel r ;
JLabel result ;
JButton bin ;

public MyDecimalToBinary(){
myPanel = new JPanel(new GridLayout(4 ,2, 20 ,0 ));
number = new JTextField(10);
bin = new JButton("bin");

r = new JLabel(" Enter a number : ");
result = new JLabel("decimal to bin = ");
bin.addActionListener(this);
myPanel.add(r);
myPanel.add(number);
myPanel.add(result);
myPanel.add(bin);
this.add(myPanel);

}
public static void main(String[] args) {
MyDecimalToBinary first=new MyDecimalToBinary();
first.setTitle("Decimal to Binary");
first.setSize(300,200);
first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
first.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
if( event.getSource() == bin){
int decimal =Integer.parseInt(number.getText()) ;
String bin="";
while(decimal!=0){
bin=decimal%2+bin;
decimal/=2;
}
result.setText(""+bin);
}
}

}

0 التعليقات:

لعبة من سيربح المليون لعبة زوما