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

ما الخطأ فى هذا الكود(استخدام اوبجكت من كلاس فى كلاس اخر)

مغلق
بدأه microsmart1 في 13 نوفمبر 2006 · 1 رد · 619 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع
//first class
class myframe2 extends JFrame

 {
 	ImageIcon img=new ImageIcon("D:\\Mastering Java\\Java Projects\\Icons\\alert_lrg.gif ");

	JLabel lbl=new 	JLabel(" Do You Love Computer Science?",img,JLabel.LEFT);

	 JPanel pnl3=new JPanel();

	 myframe2()
	 {
	 	setupgui();	 	
	 }

	 private void setupgui()

	 {
	 	setSize(150,150);
	 	setTitle("Error");


	 	Container c2=getContentPane();;


	 	pnl3.setLayout(new BorderLayout());


		lbl.setIcon(img);

	   	pnl3.add("Center",lbl);

	   	c2.add(pnl3);

	   	setVisible(true);


	 }	 
 }  




//second class


 class MyInner implements ActionListener	  
   {


	 public void actionPerformed(ActionEvent e)
	 {


		  if(!txt1.getText().equals("Name1") && !txt2.getText().equals("Name2"))
		  {




			 	if (e.getActionCommand().equals("Result"))
				{


//First process
int random= ((int)(50*Math.random()))+50;
 txt3.setText(random+"%");

 //second process

String  msg[ ]={"Love Can Touch Us One Time And Last For The Life Time\nYou Are A True Lovers.","Your Feelings Are Different \nYou Should Forget it."
,"Love Is A Passion\nYou Must Be More Romantic.","You Are An Angel\n But Your Lover Is A Liar."
,"You Must Think Deeply Before That Choice\nLove Is Not An Entertainment.","Do Not Lie To Your Hart\nYou Still Love Your First Lover."
,"You Cannot Love Again\nYour First Lover is So Lovely And Cannot Be Forotten."}; 






		ta.setText(  msg[((int)( msg.length*Math.random()))]	);
		/* breaking up the code
		double random = Math.random();
		int index = (int) (msg.length*random);
	   String message = msg[index];
	   ta.setText(message);*/

		ta.setForeground(Color.RED);

			   }



		  }

		 else
		  {

			c2.setSelected(true);


		  }
	 }

	 }

الخطأ هنا

c2.setSelected(true);

cannot resolve simple variable c2

كيف اصحح هذا الخطأ

#2

/first class

class myframe2 extends JFrame

{

ImageIcon img=new ImageIcon("D:\\Mastering Java\\Java Projects\\Icons\\alert_lrg.gif ");

JLabel lbl=new JLabel(" Do You Love Computer Science?",img,JLabel.LEFT);

JPanel pnl3=new JPanel();

myframe2()

{

setupgui();

}

private void setupgui()

{

setSize(150,150);

setTitle("Error");

Container c2=getContentPane();;

pnl3.setLayout(new BorderLayout());

lbl.setIcon(img);

pnl3.add("Center",lbl);

c2.add(pnl3);

setVisible(true);

}

}

//second class

class MyInner implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

if(!txt1.getText().equals("Name1") && !txt2.getText().equals("Name2"))

{

if (e.getActionCommand().equals("Result"))

{

//First process

int random= ((int)(50*Math.random()))+50;

txt3.setText(random+"%");

//second process

String msg[ ]={"Love Can Touch Us One Time And Last For The Life Time\nYou Are A True Lovers.","Your Feelings Are Different \nYou Should Forget it."

,"Love Is A Passion\nYou Must Be More Romantic.","You Are An Angel\n But Your Lover Is A Liar."

,"You Must Think Deeply Before That Choice\nLove Is Not An Entertainment.","Do Not Lie To Your Hart\nYou Still Love Your First Lover."

,"You Cannot Love Again\nYour First Lover is So Lovely And Cannot Be Forotten."};

ta.setText( msg[((int)( msg.length*Math.random()))] );

/* breaking up the code

double random = Math.random();

int index = (int) (msg.length*random);

String message = msg[index];

ta.setText(message);*/

ta.setForeground(Color.RED);

}

}

else

{

myframe2 objmyframe2 = new myframe2 ;

objmyframe2.c2.setSelected(true);

}

}

}

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

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

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

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

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

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