Results 1 to 5 of 5
  1. #1
    vknehra10 is offline Member
    Join Date
    Dec 2016
    Posts
    99
    Rep Power
    0

    Default How to access these data member?

    Java Code:
    import javax.swing.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class TimeThread extends Thread{
    
          public void call(){
        
            	 JFrame jf= new  JFrame("Time");
    	JTextField jt=new JTextField("Green");
    	JButton jb=new JButton("Start");
    	
    	
    	jf.setVisible(true);
    	jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	jf.setBounds(200,100,500,500);
    	jf.setLayout(null);
    	
    	
    	jf.add(jt);
    	jt.setBounds(200,200,60,60);
    	jt.setEditable(false);
    	 jt.setBackground(Color.GREEN);
    	
    	
    	//jf.add(jb);
    	//jb.setBounds(150,250,80,50);
    	
        
         
            
        }   
    public void run(){                                                        
    jt.setBackground(Color.Red);                 //showing compile time error:- Can't Find Symbol how to fix?
    }
    	 
    	  
        public static void main(String Dev[]){
    		
    	TimeThread tt=new TimeThread();
    	Thread t=new Thread(tt);
    	t.start();
    	tt.call();
        
          
        }
    Last edited by vknehra10; 08-12-2017 at 08:13 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,942
    Rep Power
    30

    Default Re: How to access these data member?

    Make sure the variables are defined at the class level. variables defined locally inside of a method are not accessible in another method.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    vknehra10 is offline Member
    Join Date
    Dec 2016
    Posts
    99
    Rep Power
    0

    Default Re: How to access these data member?

    Quote Originally Posted by Norm View Post
    Make sure the variables are defined at the class level. variables defined locally inside of a method are not accessible in another method.
    so now what to do to access "jt"

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,942
    Rep Power
    30

    Default Re: How to access these data member?

    Did you move the definition for the variables out of the method to the class level?
    That will allow any method to access the variables.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,942
    Rep Power
    30

    Default Re: How to access these data member?

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: 05-23-2015, 09:05 PM
  2. Replies: 11
    Last Post: 02-18-2014, 03:04 PM
  3. Replies: 15
    Last Post: 03-28-2013, 06:32 PM
  4. protected data member
    By javanoobe in forum New To Java
    Replies: 11
    Last Post: 04-15-2011, 09:09 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •