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

طلب مساعدة تعديل في كود آله حاسبه

بدأه the night في 25 مايو 2011 · 3 رد · 489 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

هادا كود آله حاسبه سويتو لكن الاله ما بتشتغل يعني بيطلع الانترفيس تمام

بس لما اضغط عليها ما بطلع شي

ارجو منكم تقولولي ايش المشكله فيها و شكرا

الكود في المرفقات

Calc.java

#2

تفضلى

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

public class Calc implements ActionListener {

	JTextArea textArea;
	JFrame calculator;
	JPanel panel;
	JPanel panel2;
	JButton button1;
	JButton button2;
	JButton button3;
	JButton button4;
	JButton button5;
	JButton button6;
	JButton button7;
	JButton button8;
	JButton button9;
	JButton button0;
	JButton buttonadd;
	JButton buttonsub;
	JButton buttonmul;
	JButton buttondiv;
	JButton buttonsqr;
	JButton buttoneq;
	JButton buttonclear;
	JButton buttonclose;
	JButton buttonhelp;
	String text;

	public static void main(String[] args) {
    	Calc c = new Calc();
    	c.init();
	}

	private void init() {
    	calculator = new JFrame();
    	calculator.setSize(300, 300);
    	calculator.setTitle("Calculator ^^");

    	button1 = new JButton("1");
    	button2 = new JButton("2");
    	button3 = new JButton("3");
    	button4 = new JButton("4");
    	button5 = new JButton("5");
    	button6 = new JButton("6");
    	button7 = new JButton("7");
    	button8 = new JButton("8");
    	button9 = new JButton("9");
    	button0 = new JButton("0");
    	buttonadd = new JButton("+");
    	buttonsub = new JButton("-");
    	buttonmul = new JButton("*");
    	buttondiv = new JButton("/");
    	buttonsqr = new JButton("sqr");
    	buttoneq = new JButton("=");
    	buttonclear = new JButton("C");
    	buttonclose = new JButton("close");
    	buttonhelp = new JButton("help");

    	textArea = new JTextArea(1, 21);

    	Container c = calculator.getContentPane();

    	c.setLayout(new GridLayout(3, 1, 2, 2));

    	c.setBackground(Color.black);



    	panel = new JPanel(new GridLayout(4, 4));
    	panel2 = new JPanel(new GridLayout(1, 3));



    	button1.setName("1");
    	button2.setName("2");
    	button3.setName("3");
    	button4.setName("4");
    	button5.setName("5");
    	button6.setName("6");
    	button7.setName("7");
    	button8.setName("8");
    	button9.setName("9");
    	button0.setName("0");
    	buttonadd.setName("+");
    	buttonsub.setName("-");
    	buttonmul.setName("*");
    	buttondiv.setName("/");
    	buttonsqr.setName("sqr");
    	buttoneq.setName("=");
    	buttonclear.setName("C");
    	buttonclose.setName("Close");
    	buttonhelp.setName("help");


    	panel.add(button1);
    	panel.add(button2);
    	panel.add(button3);
    	panel.add(buttonsqr);

    	panel.add(button4);
    	panel.add(button5);
    	panel.add(button6);
    	panel.add(buttonmul);

    	panel.add(button7);
    	panel.add(button8);
    	panel.add(button9);
    	panel.add(buttondiv);

    	panel.add(button0);
    	panel.add(buttonadd);
    	panel.add(buttonsub);
    	panel.add(buttoneq);

    	panel2.add(buttonclear);
    	panel2.add(buttonclose);
    	panel2.add(buttonhelp);


    	button1.addActionListener(this);
    	button2.addActionListener(this);
    	button3.addActionListener(this);
    	button4.addActionListener(this);
    	button5.addActionListener(this);
    	button6.addActionListener(this);
    	button7.addActionListener(this);
    	button8.addActionListener(this);
    	button9.addActionListener(this);
    	button0.addActionListener(this);
    	buttonadd.addActionListener(this);
    	buttonsub.addActionListener(this);
    	buttonmul.addActionListener(this);
    	buttondiv.addActionListener(this);
    	buttoneq.addActionListener(this);
    	buttonclear.addActionListener(this);
    	buttonsqr.addActionListener(this);
    	buttonhelp.addActionListener(this);

    	c.add(textArea);

    	c.add(panel);

    	c.add(panel2);

    	calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	calculator.setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {

    	Double number1, number2, result;
    	int addc = 0, subc = 0, multic = 0, divc = 0, squarec = 0;


    	//	buttonhelp.addActionListener(new ActionListener(){
//    	JOptionPane.showMessageDialog(null, "This Program is Version 1.0\n" + "Teams Name : \n");

    	Object source = e.getSource();


    	if (source == buttonclear) {
        	number1 = 0.0;
        	number2 = 0.0;
        	textArea.setText("");
    	}


    	if (source == button1) {
        	textArea.append("1");
    	}

    	if (source == button2) {

        	textArea.append("2");
    	}

    	if (source == button3) {

        	textArea.append("3");
    	}
    	if (source == button4) {
        	textArea.append("4");
    	}
    	if (source == button5) {
        	textArea.append("5");
    	}
    	if (source == button6) {
        	textArea.append("6");
    	}
    	if (source == button7) {
        	textArea.append("7");
    	}
    	if (source == button8) {
        	textArea.append("8");
    	}
    	if (source == button9) {
        	textArea.append("9");
    	}
    	if (source == button0) {
        	textArea.append("0");
    	}

    	if (source == buttonadd) {
        	number1 = number_reader();
        	textArea.setText("");
        	addc = 1;
        	subc = 0;
        	multic = 0;
        	divc = 0;
        	squarec = 0;
    	}
    	if (source == buttonsub) {
        	number1 = number_reader();
        	textArea.setText("");
        	addc = 0;
        	subc = 1;
        	multic = 0;
        	divc = 0;
        	squarec = 0;
    	}
    	if (source == buttonmul) {
        	number1 = number_reader();
        	textArea.setText("");
        	addc = 0;
        	subc = 0;
        	multic = 1;
        	divc = 0;
        	squarec = 0;
    	}
    	if (source == buttondiv) {
        	number1 = number_reader();
        	textArea.setText("");
        	addc = 0;
        	subc = 0;
        	multic = 0;
        	divc = 1;
        	squarec = 0;
    	}
    	if (source == buttonsqr) {
        	number1 = number_reader();
        	result = Math.pow(number1, 2);
        	textArea.setText("" + result);
        	addc = 0;
        	subc = 0;
        	multic = 0;
        	divc = 0;
        	squarec = 1;
    	}
    	if (source == buttoneq) {
        	number2 = number_reader();

        	if (addc != 0) {
            	number1 = number_reader();
            	number2 = number_reader();
            	result = number1 + number2;
            	textArea.setText(Double.toString(result));

        	}
        	if (subc == 1) {
            	number1 = number_reader();
            	number2 = number_reader();
            	result = number1 - number2;
            	textArea.setText(Double.toString(result));

        	}

        	if (multic == 1) {
            	number1 = number_reader();
            	number2 = number_reader();
            	result = number1 * number2;
            	textArea.setText(Double.toString(result));

        	}

        	if (divc == 1) {
            	number1 = number_reader();
            	number2 = number_reader();
            	result = number1 / number2;
            	textArea.setText(Double.toString(result));
        	}
    	}
	}

	public double number_reader() {
    	Double num1;
    	String s;
    	s = textArea.getText();
    	num1 = Double.valueOf(s);
    	return num1;
	}
}

Software Developer
Mahmoudkelany.com


 

#3

شكرا جزيلا

لكن ازرار = و help ما بتشتغل

#4

دحين خلاص عدلت الازارير الباقيه

بس باقي ازرار ال=

مررررررررررررررررررررررره مو راضي مررررره تعبني

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

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

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

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

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