اليوم حابب افرجيكم كود كالكوليتر بس بشكل مبسط بالجافا
ان شاء الله يعجبكم
ملحوظة : شكل البرنامج مقلوب لكن انسخه وحطه على نوت باد وراح يكون بشكله الصحيح
وهذا هو الكود.....لعيونكم
//mohammad qassim almolijy
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class calculator extends JFrame implements ItemListener,ActionListener
{
private JTextField txt1,txt2,txt3;
private JRadioButton sum,sub,mul,div;
private ButtonGroup grp=new ButtonGroup();
private JLabel lbl1,lbl2,lbl3;
private JButton cal=new JButton("="),clear=new JButton("C");
private JPanel p1=new JPanel(),p2=new JPanel(),p3=new JPanel();
private GridLayout grid=new GridLayout(3,1);
private double x,y,z;
public calculator()
{super("Calculator");
cal.setBackground(Color.green);
clear.setBackground(Color.green);
Container con=getContentPane();
con.setLayout( grid);
txt1=new JTextField(10);
txt2=new JTextField(10);
txt3=new JTextField(10);
p1.add(txt1);
txt1.setBackground(Color.yellow);
txt2.setBackground(Color.yellow);
txt3.setBackground(Color.pink);
http://txt1.setFont(new Font("Serif", Font.PLAIN, 20 ));
sum=new JRadioButton(" + ");
sub=new JRadioButton(" - ");
mul=new JRadioButton(" X ");
div=new JRadioButton(" / ");
p1.add(sum);
p1.add(sub);
p2.add(txt2);
p3.add(txt3);
p3.add(cal);
p3.add(clear);
p2.add(mul);
p2.add(div);
grp.add(sum);
grp.add(sub);
grp.add(mul);
grp.add(div);
con.add(p1);
con.add(p2);
con.add(p3);
p1.setBackground(Color.blue);
p2.setBackground(Color.blue);
p3.setBackground(Color.blue);
http://sum.setBackground(Color.red);sum.addItemListener( this);
sub.addItemListener( this);
mul.addItemListener( this);
div.addItemListener( this);
cal.addActionListener( this);
clear.addActionListener( this);
setBounds(400,400,250,140);
setVisible(true);
}
public void itemStateChanged(ItemEvent event)
{
x=Double.parseDouble(txt1.getText());
y=Double.parseDouble(txt2.getText());
if(event.getSource()==mul && mul.isSelected())
z=x*y;
else if(event.getSource()==sub && sub.isSelected())
z=x-y;
else if(event.getSource()==div && div.isSelected())
z=x/y;
else
z=x+y;
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==cal)
txt3.setText(""+(z));
if(event.getSource()==clear)
{
txt1.setText("");
txt2.setText("");
txt3.setText("");
txt1.requestFocus();
}
}
public static void main(String arg[])
{
calculator m=new calculator();
}
}