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

[مغلق - سؤال مخالف]مساعده في برنامج gui

مغلق
بدأه سدوووم في 23 أبريل 2012 · 3 رد · 503 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

عندي مشكله في اتمام برنامج لحساب السعرات الحراريه الـ event عندي فيه خطأ بس مدري ايش ..!

هذي محاولتي في حله

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project1;

/**
 *
 */
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class Calorie extends JFrame {

    /**
     * @param args the command line arguments
     */
    private String active[] ={ "Sedentary", "Light Active", "Moderately Active", "Very Active", "Extra Active" };
    private JPanel p1;
    private JPanel p2;
    private JPanel p3;
    private JPanel p4;
    private JPanel p5;
    private JPanel p6;
    private JPanel p7;
    private JPanel p8;
    private JPanel p9;
    private JPanel p10;
    private JPanel p11;
    private JPanel p12;
    private JPanel p13;
    private JPanel p14;
    private JPanel p15;
    private JLabel l1;
    private JLabel l2;
    private JLabel l3;
    private JLabel l4;
    private JLabel l5;
    private JLabel l6;
    private JLabel l7;
    private JLabel l8;
    private JLabel l9;
    private JLabel l10;
    private JTextField t1;
    private JTextField t2;
    private JTextField t3;
    private JTextField t4;
    private JTextField t5;
    private JTextField t6;
    private JTextField t7;
    private JTextField t8;
    private JRadioButton r1;
    private JRadioButton r2;
    private JComboBox c1;
    private JButton b1;
    public Calorie()
    {
        super("Calorie Calculator");
    setBackground(Color.PINK);
    p1= new JPanel();
    p2= new JPanel();
    p3= new JPanel();
    p4= new JPanel();
    p5= new JPanel();
    p6= new JPanel();
    p7= new JPanel();
    p8= new JPanel();
    p9= new JPanel();
    p10= new JPanel();
    p11= new JPanel();
    p12= new JPanel();
    p13= new JPanel();
    p14= new JPanel();
    p15= new JPanel();
        l1= new JLabel("Age: ");
        p1.add(l1);
        t1= new JTextField(5);
        p1.add(t1);
        l2= new JLabel("Gender: ");
        p2.add(l2);
        r1= new JRadioButton("Male",true);
        p2.add(r1);
        r2= new JRadioButton("Female",false);
        p2.add(r2);
        l3= new JLabel("Height(cm): ");
        p3.add(l3);
        t2=new JTextField(5);
        p3.add(t2);
        l4= new JLabel("Weight(kg): ");
        p4.add(l4);
        t3=new JTextField(5);
        p4.add(t3);
        l4= new JLabel("Activeness: ");
        p5.add(l4);
        c1= new JComboBox(active);
        c1.setMaximumRowCount( 5 );
        p5.add(c1);
        b1= new JButton("Calculate the Calorie");
        p6.add(b1);
        l5= new JLabel("Calorie-Result");
        p7.add(l5);
        l6= new JLabel("Calorie Needed: ");
        p8.add(l6);
        t4= new JTextField(15);
        p8.add(t4);
        l6= new JLabel("You must Intake the following daily");
        p9.add(l6);
        l7= new JLabel("         Fat: ");
        p10.add(l7);
        t5= new JTextField(15);
        p10.add(t5);
        l8= new JLabel("       Protein: ");
        p11.add(l8);
        t6= new JTextField(15);
        p11.add(t6);
        l9= new JLabel("Carbohydrate: ");
        p12.add(l9);
        t7= new JTextField(15);
        p12.add(t7);
        l10=new JLabel("     Alcohol: ");
        p13.add(l10);
        t8= new JTextField(15);
        p13.add(t8);

      setLayout(new FlowLayout());
        add(p1);
        add(p2);
        add(p3);
        add(p4);
        add(p5);
        p14.add(p6);
        add(p14,BorderLayout.CENTER);
        p15.add(p7);
        add(p15,BorderLayout.SOUTH);
        add(p8);
        add(p9);
        add(p10);
        add(p11);
        add(p12);
        add(p13);
       ButtonHandler handler = new ButtonHandler();
b1.addActionListener( handler );


    }
    private class ButtonHandler implements ActionListener
    {
       private int calorie;
       private int fat;
       private int car;
       private int protein;
       private int alcohol;
       private int g; 
        @Override
       public void actionPerformed( ActionEvent event ) 
        {
           if(l1.getSource()== l1)
           {
               g=66+(13.7*weight)+(5*cm)-(6.8*age);
           }
           else if(l2.getSource()==l2)
           {
               g=655+(9.6*weight)+(1.8*cm)-(4.7*age);
           } 
           switch(active)
{
		case "1":
			calorie=g*1.2;
			break;
		case "2":
			calorie=g*1.375
			break;
		case "3":
			calorie=g*1.53;
			break;
		case "4":
			calorie=g*1.725;
			break;
		case "5":
			calorie=g*1.9;
			break;
	}
	fat=((calorie*0.25)/9);
	protein=((calorie*0.25)/4);
	car=((calorie*0.25)/4);
	alcohol=((calorie*0.25)/7);

        }
    }

    public static void main(String[] args) {
        // TODO code application logic here
        Calorie obj=new Calorie();
        obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        obj.setSize(310, 600);
        obj.setVisible(true) ; 

    }

}
#2
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;

public class Calorie extends JFrame {

	private String active[] = {"Sedentary", "Light Active", "Moderately Active", "Very Active", "Extra Active"};
	private JPanel p1;
	private JPanel p2;
	private JPanel p3;
	private JPanel p4;
	private JPanel p5;
	private JPanel p6;
	private JPanel p7;
	private JPanel p8;
	private JPanel p9;
	private JPanel p10;
	private JPanel p11;
	private JPanel p12;
	private JPanel p13;
	private JPanel p14;
	private JPanel p15;
	private JLabel l1;
	private JLabel l2;
	private JLabel l3;
	private JLabel l4;
	private JLabel l5;
	private JLabel l6;
	private JLabel l7;
	private JLabel l8;
	private JLabel l9;
	private JLabel l10;
	private JTextField t1;
	private JTextField t2;
	private JTextField t3;
	private JTextField t4;
	private JTextField t5;
	private JTextField t6;
	private JTextField t7;
	private JTextField t8;
	private JRadioButton r1;
	private JRadioButton r2;
	private JComboBox c1;
	private JButton b1;

	public Calorie() {
    	super("Calorie Calculator");
    	setBackground(Color.PINK);
    	p1 = new JPanel();
    	p2 = new JPanel();
    	p3 = new JPanel();
    	p4 = new JPanel();
    	p5 = new JPanel();
    	p6 = new JPanel();
    	p7 = new JPanel();
    	p8 = new JPanel();
    	p9 = new JPanel();
    	p10 = new JPanel();
    	p11 = new JPanel();
    	p12 = new JPanel();
    	p13 = new JPanel();
    	p14 = new JPanel();
    	p15 = new JPanel();
    	l1 = new JLabel("Age: ");
    	p1.add(l1);
    	t1 = new JTextField(5);
    	p1.add(t1);
    	l2 = new JLabel("Gender: ");
    	p2.add(l2);
    	r1 = new JRadioButton("Male", true);
    	p2.add(r1);
    	r2 = new JRadioButton("Female", false);
    	p2.add(r2);
    	l3 = new JLabel("Height(cm): ");
    	p3.add(l3);
    	t2 = new JTextField(5);
    	p3.add(t2);
    	l4 = new JLabel("Weight(kg): ");
    	p4.add(l4);
    	t3 = new JTextField(5);
    	p4.add(t3);
    	l4 = new JLabel("Activeness: ");
    	p5.add(l4);
    	c1 = new JComboBox(active);
    	c1.setMaximumRowCount(5);
    	p5.add(c1);
    	b1 = new JButton("Calculate the Calorie");
    	p6.add(b1);
    	l5 = new JLabel("Calorie-Result");
    	p7.add(l5);
    	l6 = new JLabel("Calorie Needed: ");
    	p8.add(l6);
    	t4 = new JTextField(15);
    	p8.add(t4);
    	l6 = new JLabel("You must Intake the following daily");
    	p9.add(l6);
    	l7 = new JLabel("     	Fat: ");
    	p10.add(l7);
    	t5 = new JTextField(15);
    	p10.add(t5);
    	l8 = new JLabel("   	Protein: ");
    	p11.add(l8);
    	t6 = new JTextField(15);
    	p11.add(t6);
    	l9 = new JLabel("Carbohydrate: ");
    	p12.add(l9);
    	t7 = new JTextField(15);
    	p12.add(t7);
    	l10 = new JLabel(" 	Alcohol: ");
    	p13.add(l10);
    	t8 = new JTextField(15);
    	p13.add(t8);

    	setLayout(new FlowLayout());
    	add(p1);
    	add(p2);
    	add(p3);
    	add(p4);
    	add(p5);
    	p14.add(p6);
    	add(p14, BorderLayout.CENTER);
    	p15.add(p7);
    	add(p15, BorderLayout.SOUTH);
    	add(p8);
    	add(p9);
    	add(p10);
    	add(p11);
    	add(p12);
    	add(p13);
    	ButtonHandler handler = new ButtonHandler();
    	b1.addActionListener(handler);


	}

	class ButtonHandler implements ActionListener {

    	private double calorie;
    	private double fat;
    	private double car;
    	private double protein;
    	private double alcohol;
    	private double g;
    	private double weight;
    	private double cm;
    	private double age;

    	@Override
    	public void actionPerformed(ActionEvent event) {
        	if (event.getSource() == b1) {
            	g = 66 + (13.7 * weight) + (5 * cm) - (6.8 * age);
        	} else if (event.getSource() == l2) {
            	g = 655 + (9.6 * weight) + (1.8 * cm) - (4.7 * age);
        	}
        	switch (c1.getSelectedIndex()) {
            	case 1:
                	calorie = g * 1.2;
                	break;
            	case 2:
                	calorie = g * 1.375;
                	break;
            	case 3:
                	calorie = g * 1.53;
                	break;
            	case 4:
                	calorie = g * 1.725;
                	break;
            	case 5:
                	calorie = g * 1.9;
                	break;
        	}
        	t4.setText(calorie + "");

        	fat = ((calorie * 0.25) / 9);
        	t5.setText(fat + "");

        	protein = ((calorie * 0.25) / 4);
        	t6.setText(protein + "");

        	car = ((calorie * 0.25) / 4);
        	t7.setText(car + "");

        	alcohol = ((calorie * 0.25) / 7);
        	t8.setText(alcohol + "");

    	}
	}

	public static void main(String[] args) {
    	Calorie obj = new Calorie();
    	obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	obj.setSize(310, 600);
    	obj.setVisible(true);
	}
}

تم تعديل هذه المشاركة بواسطة Mahmoud Kelany في 23 أبريل 2012 في 22:49

Software Developer
Mahmoudkelany.com


 

#3

مشكووور أخوي يعطيك العافيه..

ربي يرزقك الفردوس..

#4

عذرا الموضوع مغلق

للأسئلة يجب تحديد النوع سؤال وطرح نقاط عليه والحد الأدنى 3 نقاط وإلا سيغلق موضوعك فورا وسيحذف بعد ذلك حتى لو تمت الإجابة عليه .

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

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

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

728x90.png

هذا الموضوع مغلق.

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