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

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

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

public class Binarytodecimal {
public static class MyBinaryToDecimal extends JFrame implements ActionListener{
JPanel myPanel ;
JTextField number ; 
JLabel r ;
JLabel result ;
JButton decimal ;

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

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

}
public static void main(String[] args) {
MyBinaryToDecimal first=new MyBinaryToDecimal();
first.setTitle("binary to decimal");
first.setSize(300,200);
first.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
first.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent event) {
if( event.getSource() == decimal){
int n = Integer.parseInt(number.getText()) ;
String decimal=""; int p=1; int s=0;
while(n > 0){
s=s+((n%10)*p);

p=p*2;
n/=10;
}
result.setText(""+s);
}
}
}
}

0 التعليقات:

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