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

[تنبيه - عنوان غير مناسب : ]استفسار عن خطأ ..!

بدأه rawan_1990 في 1 ديسمبر 2011 · 7 رد · 994 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
public void actionPerformed(ActionEvent e) {


        int i=0;
        String s1 =" Others look at you as a person should be treated with caution \n May admire you,"
                +"and everyone else would like to be like you, but do not trust you always,"
                +" \n and are reluctant to form a deep relationship with you.";

        String s2 ="Others look at you as a person is sensitive, careful, cautious, practical \n "
                +".. To build social relationships can not quickly or easily, but dedicated to his friends,\n requiring them to reciprocity.";

        String s3 =" Others look at you as a person is shy, concern, he can not take Decisions, needs to be sponsored by,\n"
                +"always need to take him from Decisions, does not want to interfere in anything or anyone.";

            if(e.getSource()==a)
            i=i+2;
            else if(e.getSource()==b)
        i=i+4;
        else if(e.getSource()==c)
        i=i+6;

            if (e.getSource()==end){
        if(i<=10)
    JOptionPane.showMessageDialog(null,s1,"Analysis of your personality is ",JOptionPane.PLAIN_MESSAGE);
    else if(i>=11||i<=20)
    JOptionPane.showMessageDialog(null,s2,"Analysis of your personality is ",JOptionPane.PLAIN_MESSAGE);
        else if(i>20)
    JOptionPane.showMessageDialog(null,s3,"Analysis of your personality is ",JOptionPane.WARNING_MESSAGE);
            }

        }

البرنامج عباره عن اختبار 5 اسئلة وكل سؤال له 3اخنياري a-b-c والخيارات عباره عن JRadioButton

بحيث اذا اختار المُختبِر a يزود العداد i نقطتين واذا اختار b يزود 4نقاط وهكذا ...

بعد مايخلص المُختبِر من الاختيار يضغط على button (end)

وعمل if الثانيه هو : اذا كان العداد ( i<=10 ) يطبع لي s1 في dialog وهكذا كما موضح في البرنامج

abolkog & FAZ شكراً لكم مقدماً : )

تم تعديل هذه المشاركة بواسطة Abdullah.Alshammeri في 4 ديسمبر 2011 في 16:50 — السبب: تعديل السؤال من مشاركة أخرى لكاتبة الموضو

−1
#2

المشكلة إنك بتعرفى اللمتغير i داخل الكود الخاص بال actionPerformed

public void actionPerformed(ActionEvent e) {


int i=0;
.
.
.

، وبالتالى كل مره يتم الضغط على زر قيمة ال i تسترجع الى الصفر و يتم حسابها من جديد

اذا قيمة ال i ستظل دائما اقل من 10 ولذلك اسيتم دائماً تنفيذ القاعده الأولى من ال If statement

غيرى التعريف الخاص إلى مكان اخر بالكود

مثال

public class QuestionsGame extends JFrame implements ActionListener{

	JButton a = new JButton("a");
	JButton b = new JButton("b");
	JButton c = new JButton("c");

	int i = 0;  //Declare I here not inside actionperfomed method

	public QuestionsGame(){
		a.addActionListener(this);
		b.addActionListener(this);
		c.addActionListener(this);

		JPanel buttonsPanel = new JPanel();
		buttonsPanel.add(a,BorderLayout.EAST);
		buttonsPanel.add(b,BorderLayout.CENTER);
		buttonsPanel.add(c,BorderLayout.WEST);

		add(buttonsPanel);


		setSize(250, 205);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);

	}
	@Override
	public void actionPerformed(ActionEvent e) {

		if(e.getSource() == a)
			i +=2;
		else if(e.getSource() == b)
			i +=4;
		else if(e.getSource() == c)
			i += 6;


		JOptionPane.showMessageDialog(this, "i = " + i);

	}



	public static void main(String[] args) {
		new QuestionsGame();
	}

تم تعديل هذه المشاركة بواسطة abolkog في 2 ديسمبر 2011 في 08:38

1
#3

abolkog مشكور جداً : )

لكن مازال الخطأ موجود .. ممكن ايميلك لو سمحت عشان ارسلك البرنامج كامل ؟

لاني مااقدر اراسلك على الخاص .. : )

#4

لو سمحتوا كيف اقدر اكرر استخدام نفس JRadioButton اكثر من مره : (

يعني JRadioButton a ,b,c اكررها بكل الاسئله الخمسه اللي في البرنامج !!

تم تعديل هذه المشاركة بواسطة rawan_1990 في 2 ديسمبر 2011 في 17:15

−1
#5

أختى الكريمه جربى هذا الكود

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


public class QuestionsGame extends JFrame implements ActionListener
{

        int i = 0;  //Declare I here not inside actionperfomed method

        String s1 =" Others look at you as a person should be treated with caution \n May admire you,"
        +"and everyone else would like to be like you, but do not trust you always,"
        +" \n and are reluctant to form a deep relationship with you.";

        String s2 ="Others look at you as a person is sensitive, careful, cautious, practical \n "
        +".. To build social relationships can not quickly or easily, but dedicated to his friends,\n requiring them to reciprocity.";

        String s3 =" Others look at you as a person is shy, concern, he can not take Decisions, needs to be sponsored by,\n"
        +"always need to take him from Decisions, does not want to interfere in anything or anyone.";

        public  QuestionsGame()
        {
                JRadioButton a = new JRadioButton("a");
                JRadioButton b = new JRadioButton("b");
                JRadioButton c = new JRadioButton("c");     	
                JButton end = new JButton("end"); 


                //Group the radio buttons.
                ButtonGroup group = new ButtonGroup();
                group.add(a);
                group.add(b);
                group.add(c);



                a.addActionListener(this);
                b.addActionListener(this);
                c.addActionListener(this);
                end.addActionListener(this);

                JPanel radioPanel = new JPanel();
                radioPanel.add(a,BorderLayout.EAST);
                radioPanel.add(b,BorderLayout.CENTER);
                radioPanel.add(c,BorderLayout.WEST);
                radioPanel.add(end,BorderLayout.AFTER_LAST_LINE);



                add(radioPanel);

                setSize(250, 205);
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                setVisible(true);

        }

       	public void actionPerformed(ActionEvent e)
                {

                 	if (e.getActionCommand().matches("a"))
                 	{
                     	i=i+2;
                 	}
                 	if (e.getActionCommand().matches("b"))
                 	{
                     	i=i+4;
                 	}
                 	if (e.getActionCommand().matches("c"))
                 	{
                     	i=i+6;
                 	}   
                    if (e.getActionCommand().matches("end"))

                 	{
                        if(i<=10)
                        JOptionPane.showMessageDialog(null,s1,"Analysis of your personality is ",JOptionPane.PLAIN_MESSAGE);
                        else if(i>=11||i<=20)
                        JOptionPane.showMessageDialog(null,s2,"Analysis of your personality is ",JOptionPane.PLAIN_MESSAGE);
                        else if(i>20)
                        JOptionPane.showMessageDialog(null,s3,"Analysis of your personality is ",JOptionPane.WARNING_MESSAGE);
                 	}   

                } 

        public static void main(String[] args) 
        {
                new  QuestionsGame();
        }
}
1

 وممّا زادنـــي شرفــاً وتيهــاً   **  وكدت بأخمصي أطأ الثريّا

دخولي تحت قولك يا عبادي  **   وأن صيّرت أحمد لي نبيّـاً

#6

اخوي عمرو الصعيدي مشكور جداً ..

تم ارسال رسالة على ايميلك .. : )

#7

الأخ الكريم/الأخت الكريمة

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

مرحباً بكم في منتدى الفريق العربي للبرمجة

نود تنبيهك أن العنوان غير مناسب.

الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.

وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!

قواعد المشاركة

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

logo1.png تطبيق طمأنينة ، نسخة بيتا على أندرويد

عبدالله الشمّري - Al-Shammari

CodingAlone.com

twitter @abshammeri

abshammeri AT gmail.com

github : abshammeri

#8
rawan_1990 كتب:

abolkog مشكور جداً : )لكن مازال الخطأ موجود .. ممكن ايميلك لو سمحت عشان ارسلك البرنامج كامل ؟لاني مااقدر اراسلك على الخاص .. : )

معذره على الرد المتأخر ولكنى ايام السبت والأحد لا اكون متواجد

لا اعتقد انة من الممكن وضع الايميل الخاص بى (مخالف إلى لوائح المنتدى ) لكن يمكنك إرسال راسلة على الخاص او مراسلتى عبر الموقع الخاص بى - عنوانة موجود فى الصفحة الخاصة بى

لكنى افضل وضع الاستفسارات هنا حتى تكون الفائده عامة للجميع و ربما يكون الحل على يد عضو اخر :)

تحياتى

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