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

كود لعكس حروف الكلمه او الجمله

بدأه الطالب المثابر في 9 نوفمبر 2010 · 3 رد · 704 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

لقد اتعبتكم معي ولكن اتحملوني شويه اخوتي الاعزاء

لقد قمة بكتابة كود خاص بإنشا آله حاسبه وايضن عدد من الاكواد وهي كالتالي

الكود الخاص بالأله الحاسبه وقمة بعمل عملية الجمع

package client;


import com.sun.org.apache.xpath.internal.operations.Equals;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JToolBar;

public class Frame1 extends JFrame {
private String con =null;
private double op1;
private double op2;
private int value;
boolean op1Done;
String operation="";

    private BorderLayout layoutMain = new BorderLayout();
    private JPanel panelCenter = new JPanel();
    private JMenuBar menuBar = new JMenuBar();
    private JMenu menuFile = new JMenu();
    private JMenuItem menuFileExit = new JMenuItem();
    private JMenu menuHelp = new JMenu();
    private JMenuItem menuHelpAbout = new JMenuItem();
    private JLabel statusBar = new JLabel();
    private JToolBar toolBar = new JToolBar();
    private JButton buttonOpen = new JButton();
    private JButton buttonClose = new JButton();
    private JButton buttonHelp = new JButton();
    private ImageIcon imageOpen = new ImageIcon(Frame1.class.getResource("openfile.gif"));
    private ImageIcon imageClose = new ImageIcon(Frame1.class.getResource("closefile.gif"));
    private ImageIcon imageHelp = new ImageIcon(Frame1.class.getResource("help.gif"));
    private JTextField jTextField1 = new JTextField();
    private JLabel jLabel1 = new JLabel();
    private JButton jButton1 = new JButton();
    private JButton jButton2 = new JButton();
    private JButton jButton3 = new JButton();
    private JButton jButton4 = new JButton();
    private JButton jButton5 = new JButton();
    private JButton jButton6 = new JButton();
    private JButton jButton7 = new JButton();
    private JButton jButton8 = new JButton();
    private JButton jButton9 = new JButton();
    private JButton jButton10 = new JButton();
    private JButton jButton11 = new JButton();
    private JButton jButton12 = new JButton();
    private JButton jButton13 = new JButton();
    private JButton jButton14 = new JButton();
    private JButton jButton15 = new JButton();
    private JButton jButton16 = new JButton();

    public Frame1() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setJMenuBar( menuBar );
        this.getContentPane().setLayout( layoutMain );
        panelCenter.setLayout( null );
        this.setSize(new Dimension(400, 332));
        this.setTitle( "Calculator" );
        menuFile.setText( "File" );
        menuFileExit.setText( "Exit" );
        menuFileExit.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { fileExit_ActionPerformed( ae ); } } );
        menuHelp.setText( "Help" );
        menuHelpAbout.setText( "About" );
        menuHelpAbout.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent ae ) { helpAbout_ActionPerformed( ae ); } } );
        statusBar.setText( "" );
        buttonOpen.setToolTipText( "Open File" );
        buttonOpen.setIcon( imageOpen );
        buttonClose.setToolTipText( "Close File" );
        buttonClose.setIcon( imageClose );
        buttonHelp.setToolTipText( "About" );
        buttonHelp.setIcon( imageHelp );
        jTextField1.setBounds(new Rectangle(75, 10, 195, 20));
        jLabel1.setText("Result:");
        jLabel1.setBounds(new Rectangle(20, 10, 50, 20));
        jLabel1.setFont(new Font("Tahoma", 1, 12));
        jButton1.setText("1");
        jButton1.setBounds(new Rectangle(75, 55, 45, 25));
        jButton1.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton1_actionPerformed(e);
                    }
                });
        jButton2.setText("2");
        jButton2.setBounds(new Rectangle(145, 55, 45, 25));
        jButton2.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton2_actionPerformed(e);
                    }
                });
        jButton3.setText("3");
        jButton3.setBounds(new Rectangle(225, 55, 45, 25));
        jButton3.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton3_actionPerformed(e);
                    }
                });
        jButton4.setText("4");
        jButton4.setBounds(new Rectangle(75, 105, 45, 25));
        jButton4.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton4_actionPerformed(e);
                    }
                });
        jButton5.setText("5");
        jButton5.setBounds(new Rectangle(145, 105, 45, 25));
        jButton5.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton5_actionPerformed(e);
                    }
                });
        jButton6.setText("6");
        jButton6.setBounds(new Rectangle(225, 105, 45, 25));
        jButton6.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton6_actionPerformed(e);
                    }
                });
        jButton7.setText("7");
        jButton7.setBounds(new Rectangle(75, 155, 45, 25));
        jButton7.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton7_actionPerformed(e);
                    }
                });
        jButton8.setText("8");
        jButton8.setBounds(new Rectangle(145, 155, 45, 25));
        jButton8.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton8_actionPerformed(e);
                    }
                });
        jButton9.setText("9");
        jButton9.setBounds(new Rectangle(225, 155, 45, 25));
        jButton9.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton9_actionPerformed(e);
                    }
                });
        jButton10.setText("0");
        jButton10.setBounds(new Rectangle(145, 205, 45, 25));
        jButton10.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton10_actionPerformed(e);
                    }
                });
        jButton11.setText("=");
        jButton11.setBounds(new Rectangle(225, 205, 45, 25));
        jButton11.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton11_actionPerformed(e);
                    }
                });
        jButton12.setText(".");
        jButton12.setBounds(new Rectangle(75, 205, 45, 25));
        jButton12.setFont(new Font("Tahoma", 1, 14));
        jButton13.setText("+");
        jButton13.setBounds(new Rectangle(295, 55, 70, 25));
        jButton13.setFont(new Font("Tahoma", 1, 13));
        jButton13.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton13_actionPerformed(e);
                    }
                });
        jButton14.setText("-");
        jButton14.setBounds(new Rectangle(295, 105, 70, 25));
        jButton14.setFont(new Font("Tahoma", 1, 13));
        jButton15.setText("x");
        jButton15.setBounds(new Rectangle(295, 155, 70, 25));
        jButton15.setFont(new Font("Tahoma", 1, 13));
        jButton16.setText("CLS");
        jButton16.setBounds(new Rectangle(295, 210, 79, 22));
        jButton16.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jButton16_actionPerformed(e);
                    }
                });
        menuFile.add( menuFileExit );
        menuBar.add( menuFile );
        menuHelp.add( menuHelpAbout );
        menuBar.add( menuHelp );
        this.getContentPane().add( statusBar, BorderLayout.SOUTH );
        toolBar.add( buttonOpen );
        toolBar.add( buttonClose );
        toolBar.add( buttonHelp );
        this.getContentPane().add( toolBar, BorderLayout.NORTH );
        this.getContentPane().add( panelCenter, BorderLayout.CENTER);
        panelCenter.add(jButton16, null);
        panelCenter.add(jButton15, null);
        panelCenter.add(jButton14, null);
        panelCenter.add(jButton13, null);
        panelCenter.add(jButton12, null);
        panelCenter.add(jButton11, null);
        panelCenter.add(jButton10, null);
        panelCenter.add(jButton9, null);
        panelCenter.add(jButton8, null);
        panelCenter.add(jButton7, null);
        panelCenter.add(jButton6, null);
        panelCenter.add(jButton5, null);
        panelCenter.add(jButton4, null);
        panelCenter.add(jButton3, null);
        panelCenter.add(jButton2, null);
        panelCenter.add(jButton1, null);
        panelCenter.add(jLabel1, null);
        panelCenter.add(jTextField1, null);
        jTextField1.setEditable(false);
        setVisible(true);
    }

    void fileExit_ActionPerformed(ActionEvent e) {
        System.exit(0);
    }

    void helpAbout_ActionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(this, new Frame1_AboutBoxPanel1(), "About", JOptionPane.PLAIN_MESSAGE);
    }



    private void jButton1_actionPerformed(ActionEvent e) {
  e.equals(false);
   while (e.equals(true))
            jTextField1.setText("1");
            con = jTextField1.getText();
            jTextField1.setText(con.concat("1"));

    }


    private void jButton2_actionPerformed(ActionEvent e) {
        e.equals(false);
         while (e.equals(true))
                  jTextField1.setText("2");
                  con = jTextField1.getText();
                  jTextField1.setText(con.concat("2"));
    }

    private void jButton3_actionPerformed(ActionEvent e) {
        e.equals(false);
         while (e.equals(true))
                  jTextField1.setText("3");
                  con = jTextField1.getText();
                  jTextField1.setText(con.concat("3"));
    }

    private void jButton4_actionPerformed(ActionEvent e) {
        e.equals(false);
         while (e.equals(true))
                  jTextField1.setText("4");
                  con = jTextField1.getText();
                  jTextField1.setText(con.concat("4"));
    }

    private void jButton5_actionPerformed(ActionEvent e) {


        jTextField1.setText(jTextField1.getText()+"5");
        con = jTextField1.getText();
//        if(op1Done)
//       { op2 = Double.parseDouble(con);
//       op1Done= !op1Done;
//       }

    }

    private void jButton6_actionPerformed(ActionEvent e) {



        jTextField1.setText(jTextField1.getText()+"6");
        con = jTextField1.getText();

    }

    private void jButton7_actionPerformed(ActionEvent e) {
        e.equals(false);
         while (e.equals(true))
                  jTextField1.setText("7");
                  con = jTextField1.getText();
                  jTextField1.setText(con.concat("7"));
    }

    private void jButton8_actionPerformed(ActionEvent e) {
        e.equals(false);
         while (e.equals(true))
                  jTextField1.setText("8");
                  con = jTextField1.getText();
                  jTextField1.setText(con.concat("8"));
    }

    private void jButton9_actionPerformed(ActionEvent e) {
        e.equals(false);
         while (e.equals(true))
                  jTextField1.setText("9");
                  con = jTextField1.getText();
                  jTextField1.setText(con.concat("9"));
    }

    private void jButton10_actionPerformed(ActionEvent e) {
        e.equals(false);
         while (e.equals(true))
                  jTextField1.setText("0");
                  con = jTextField1.getText();
                  jTextField1.setText(con.concat("0"));
    }

    private void jButton13_actionPerformed(ActionEvent e) {

        System.out.println(con);
        jTextField1.setText("");
        if(!op1Done)
        op1= Double.parseDouble(con);
//        else 
//            op2= Double.parseDouble(con);
//        
        operation = "+";
        op1Done = !op1Done;


    }

    private void jButton11_actionPerformed(ActionEvent e) {

        if(op1Done)
        {
        op2 = Double.parseDouble(con);
        op1Done= !op1Done;
        }

    if(operation.equals("+"))
    jTextField1.setText(new Double(op1+op2).toString());
    }

    private void jButton16_actionPerformed(ActionEvent e) {
        jTextField1.setText("");
    }
}

والكود الاخر ببساطه يقوم بتحويل العملات من الدولار إلى الريال

    private void jButton1_actionPerformed(ActionEvent e) {
    String value = jTextField1.getText();
    double dollars = Double.parseDouble(value);
    double sr = dollars * 3.5;
    jLabel2.setText("Result In SR = "+sr);
  }

وكود ايضاً بسيط يقوم بعد عدد الكلمات في الجمله

    private void jButton1_actionPerformed(ActionEvent e) {
        jLabel2.setText("Word Count is : "+new Integer(jTextArea1.getText().split(" ").length).toString());
    }

ولكن ما اريد معرفته ايضاً كيف اعمل كود يقوم بدل من طباعة الجمله او الكلمه كما هيا كما في المثال التالي

    String value = jTextField1.getText();

    jLabel2.setText(value);
  }

اريد ان يطبع ليه الكلام بالعكس يعني اكتب كلمة (name ) في jTextField تنطبع في الـ jLabel معكوسة الحروف (eman)

ارجو ان لا اكون قد اثقلت عليكم بالأسئله

#2
import java.util.*;


public class Test1
{

	public static void main ( String[] args)
	{

		String name = "name";
		int i = name.length();
		while(i-- > 0){
			System.out.print( name.charAt(i) );
		}

	}

}

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

import java.util.*;


public class Test1
{

	public static void main ( String[] args)
	{

		String name = "name";
		StringBuffer result = new StringBuffer(name);
		System.out.println( result.reverse().toString() );
	}

}

تحياتى

تم تعديل هذه المشاركة بواسطة Oracle_Java في 9 نوفمبر 2010 في 17:58


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#3

اخي الكريم اشكرك لكن انا اريد ان اضعه في بتن اريد فقط تعديل على الكود التالي

   String value = jTextField1.getText(); 

    jLabel2.setText(value); 
  }
1 −2
#4

اشكركم اخوتي الكرام

لقد قمت بتنفيذ الكود بمساعدة اخي الفاضل Oracle_Java شكراً لك اخي الكريم وجعله الله في ميزان حسناتك وهذا هوا الكود

    private void jButton1_actionPerformed(ActionEvent e) {
        String value = jTextField1.getText();
                        StringBuffer result = new StringBuffer(value); 
      jLabel1.setText( result.reverse().toString());
    }
1

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

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

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

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

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