الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

هذي الحاسبه عملت بطريقة Oop ؟

بدأه thesharp في 19 أغسطس 2009 · 6 رد · 805 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

اخوتي الاعزاء ما رايكم بهذا الكود وجدته في المنتدى عبارة عن اله حاسبة

بواجهه رسومية جميلة



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

public class calculator extends JFrame {


public JTextField Text3;
public JButton Button0,Button1,Button2,Button3,Button4,Button5,Button6,
Button7,Button8,Button9,btn1,btn2,btn3,btn4,clear,equal;


public String Calc = "", opration = "";
public double number1 = 0,number2 = 0;


public calculator (){
super("Calculator");



Container container = getContentPane();
container.setLayout(new FlowLayout());


Text3= new JTextField(15);
Text3.setEditable(false);
container.add(Text3);



Button0 = new JButton("0");
container.add(Button0);
Button0.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 0;
Text3.setText(Calc);
}
}
);


Button1 = new JButton("1");
container.add(Button1);
Button1.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 1;
Text3.setText(Calc);
}
}
);



Button2 = new JButton("2");
container.add(Button2);
Button2.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 2;
Text3.setText(Calc);
}
}
);


Button3 = new JButton("3");
container.add(Button3);
Button3.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 3;
Text3.setText(Calc);
}
}
);


Button3 = new JButton("3");
container.add(Button3);
Button3.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 3;
Text3.setText(Calc);
}
}
);


Button4 = new JButton("4");
container.add(Button4);
Button4.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 4;
Text3.setText(Calc);
}
}
);


Button5 = new JButton("5");
container.add(Button5);
Button5.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 5;
Text3.setText(Calc);
}
}
);


Button6 = new JButton("6");
container.add(Button6);
Button6.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 6;
Text3.setText(Calc);
}
}
);


Button7 = new JButton("7");
container.add(Button7);
Button7.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 7;
Text3.setText(Calc);
}
}
);


Button8 = new JButton("8");
container.add(Button8);
Button8.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 8;
Text3.setText(Calc);
}
}
);


Button9 = new JButton("9");
container.add(Button9);
Button9.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
Calc+= 9;
Text3.setText(Calc);
}
}
);


btn1 = new JButton("+");
container.add(btn1);
btn1.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
number1 = Integer.parseInt(Text3.getText());
opration = "+";
Calc = "";
// Text3.setText("");
}
}
);


btn2 = new JButton("-");
container.add(btn2);
btn2.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
number1 = Integer.parseInt(Text3.getText());
opration = "-";
Calc = "";
// Text3.setText("");
}
}
);


btn3 = new JButton("*");
container.add(btn3);
btn3.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
number1 = Integer.parseInt(Text3.getText());
opration = "*";
Calc = "";
// Text3.setText("");
}
}
);


btn4 = new JButton("/");
container.add(btn4);
btn4.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
number1 = Integer.parseInt(Text3.getText());
opration = "/";
Calc = "";
// Text3.setText("");
}
}
);


clear = new JButton("C");
container.add(clear);
clear.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
number1 = 0;
number2 = 0;
Calc = "";
Text3.setText("");
}
}
);


equal = new JButton("=");
container.add(equal);
equal.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event){
number2 = Integer.parseInt(Text3.getText());
if (opration == "+"){
Text3.setText(number1 + number2+"");
}
if (opration == "-"){
Text3.setText(number1 - number2+"");
}
if (opration == "*"){
Text3.setText(number1 * number2+"");
}
if (opration == "/"){
Text3.setText(number1 / number2+"");
}
}
}
);
}


public static void main (String[] args) {
calculator cal = new calculator ();
cal.setSize(220,220);
cal.setVisible(true);
cal.setDefaultCloseOperation(EXIT_ON_CLOSE);
}


}

هل عمل بطريقة oop وما علامة ذلك

تم تعديل هذه المشاركة بواسطة thesharp في 19 أغسطس 2009 في 07:20

#2

البرمجة في الـ Java كلها OOP

لاحظ أن المبرمج لم يضع الشفرة المصدرية في الدالة Main مباشرة و إنما أنشأ صنفا (class)

public class calculator extends JFrame
#3

لن تجد أبداً من يقول لك هذه برمجة كائنية

أو برمجة عادية

الموضوع يتلخص في خبرة المبرمج

تستطيع القول نوعية من تنظيم الشيفرة بحيث يسهل فهمها وتعديلها في المستقبل

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#4

لكن أخي علاء ألا ترى أن كل برنامج java (شرط أن لا يوضع كل شيء في الدالة main) عبارة عن برمجة كائنية

بعض النظر عن استعمال كل قوة البرمجة الكائنية

#5

المشكلة أحياناً أن البعض يستخدم البرمجة الكائنية بطريقة البرمجة الهيكلية structural

مما يجعل الشيفرة أسوأ من الشيفرة المبرمجة على البرمجة الهيكلية

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#6

شكرا على مروركم

لكن حيرتوني زياده

تقبلوا تحياتي

#7

يا أخي الموضوع لا يأتي من أول مرة

الموضوع يحتاج إلى شغل وتعب

قراءة كتب وقراء شيفرات الآخرين وكتابة شيفراتك الخاصة

كل هذه علامات على طريف الاحتراف

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…