File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes life/death? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "life/death?" Watch "life/death?" New topic
Author

life/death?

grover_mickey
Greenhorn

Joined: Jun 27, 2001
Posts: 2
hello guys,
i am calling method of a class Two(extending JFrame) from within
constructor Class One(implementing Runnable)
steps:
1.i made the object of class two in a thread in class one and calls a method of it there in run.ex:thread.run() in one()//constructor
2.now,i call same method of class two,thsi time in constructor
one() after i call thread.run() in one()but it is giving null pointer exception
i also used thread.join() but doing that the two loses it's component and shows empty frame.
my coding is
mport java.util.*;
import java.sql.*;
import java.awt.*;
public class One implements Runnable
{ public Thread thread=new Thread(this);

public Process p;
public Logout logout;
public String Login_Name,Time_db,login_time;

public One(String str1,String str2,String str3) //name,time,client_machine
{
//Runtime r=Runtime.getRuntime();
//Process p=null;
Convert one;
//Thread thread;
int Time_db_hr,Time_db_min,current_hr,current_min,check_time_hr,check_time_min,alarm_hr,alarm_min;
String current_time,alarm_time,check_time,updated_time_bought,updated_time_bought_hr,updated_time_bought_min,str2_hr,str2_min;
StringTokenizer st1,st2,st3,st4;
Connection con;
Statement stmt=null,stmt2=null,stmt3=null,stmt4=null;
ResultSet result=null,result2=null;
String sql1,sql2,sql3;
boolean bool=true;
Current_Time systime;
Login_Name=str1;
String guest="guest";
String switching_time;
//Logout logout;
//thread=new Thread(this);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:userdsn","scott","tiger");

if((str2.compareTo("00:00"))!=0)
{
one=new Convert();
Time_db=one.con(str2);//postclocktime

//switching_time=Time_db;

st1=new StringTokenizer(Time_db,":");
Time_db_hr=Integer.parseInt(st1.nextToken());
Time_db_min=Integer.parseInt(st1.nextToken());
System.out.println("time in execdemo"+Time_db);
//p=r.exec("c:\\Program Files\\Internet Explorer\\IEXPLORE.exe");
System.out.println("After explorer");
systime=new Current_Time();
current_time=systime.current_time_fun();

login_time=current_time;


thread.start();
System.out.println("thread is"+Thread.currentThread()+thread);
System.out.println("logintime= "+login_time+" Switching Time= "+Time_db);

//try{p=logout.LogoutFunction(login_time,Time_db);}catch(Exception e){System.out.println("pakar"+e);}
switching_time=Time_db;
System.out.println("back to exedemo");

st4=new StringTokenizer(current_time,":");
current_hr=Integer.parseInt(st4.nextToken());
current_min=Integer.parseInt(st4.nextToken());

if(current_min<=9)<br /> {<br /> current_time=current_hr+":0"+current_min;<br /> }<br /> else<br /> {<br /> current_time=current_hr+":"+current_min;<br /> }<br /> <br /> <br /> <br /> <br /> while (!(current_time.equals(Time_db)))<br /> { <br /> System.out.println("deepak"); <br /> //try{<br /> p=logout.LogoutFunction(login_time,Time_db);<br /> <br /> // }catch(Exception e){System.out.println("CAUGHT:->"+e);}
System.out.println("switching off time "+Time_db);
Thread.sleep(1000);
current_time=systime.current_time_fun();
st4=new StringTokenizer(current_time,":");
current_hr=Integer.parseInt(st4.nextToken());
current_min=Integer.parseInt(st4.nextToken());

if(current_min<=9)<br /> {<br /> current_time=current_hr+":0"+current_min;<br /> }<br /> else<br /> {<br /> current_time=current_hr+":"+current_min;<br /> }<br /> System.out.print("\ncurrent time"+current_time);<br /> <br /> if(Time_db_min>=10)
{
alarm_min=Time_db_min-10;
alarm_hr=Time_db_hr;
}

else
{
alarm_hr=Time_db_hr-1;
alarm_min=Time_db_min+50;
}

if(alarm_min<=9)<br /> {<br /> alarm_time=alarm_hr+":0"+alarm_min;<br /> }<br /> else<br /> {<br /> alarm_time=alarm_hr+":"+alarm_min;<br /> }<br /> System.out.print(" alarm time"+alarm_time);<br /> <br /> <br /> if((current_time.equals(alarm_time))&& bool)<br /> {<br /> // Dialog box<br /> new AlarmDialog(new Frame());<br /> bool=false;<br /> }<br /> <br /> if(Time_db_min>=5)
{
check_time_min=Time_db_min-5;
check_time_hr=Time_db_hr;
}
else
{
check_time_hr=Time_db_hr-1;
check_time_min=Time_db_min+55;
}
if(check_time_min<=9)<br /> {<br /> check_time=check_time_hr+":0"+check_time_min;<br /> }<br /> else<br /> {<br /> check_time=check_time_hr+":"+check_time_min;<br /> }<br /> System.out.print(" check time"+check_time);<br /> <br /> if(current_time.equals(check_time))<br /> {<br /> <br /> stmt=con.createStatement();<br /> <br /> if(str1.equals(guest))<br /> {<br /> sql1="select Time_Bought from welcome where Machine_No='"+str3+"';"; <br /> System.out.println("in guest");<br /> result=stmt.executeQuery(sql1);<br /> boolean b=result.next();<br /> updated_time_bought=result.getString("Time_Bought");<br /> }<br /> else<br /> {<br /> sql1="select * from database where Login_Name='"+str1+"';";<br /> System.out.println("in registered");<br /> result=stmt.executeQuery(sql1);<br /> boolean b=result.next();<br /> updated_time_bought=result.getString("Total_Time_Remaining");<br /> } <br /> /***********************************/<br /> System.out.println("hurrayhurray!!!"+updated_time_bought);<br /> /**********************************/<br /> st2=new StringTokenizer(str2,":");<br /> st3=new StringTokenizer(updated_time_bought,":");<br /> str2_hr=st2.nextToken();<br /> str2_min=st2.nextToken();<br /> updated_time_bought_hr=st3.nextToken();<br /> updated_time_bought_min=st3.nextToken();<br /> <br /> int time_bought_hr=Integer.parseInt(updated_time_bought_hr)-Integer.parseInt(str2_hr);<br /> int time_bought_min;<br /> <br /> if(Integer.parseInt(updated_time_bought_min)>=Integer.parseInt(str2_min))
{
time_bought_min=Integer.parseInt(updated_time_bought_min)-Integer.parseInt(str2_min);
}
else
{
time_bought_min=Integer.parseInt(updated_time_bought_min)-Integer.parseInt(str2_min)+60;
time_bought_hr-=1;
}

Time_db_hr+=time_bought_hr;
Time_db_min+=time_bought_min;
if(Time_db_min>=60)
{
Time_db_min-=60;
Time_db_hr+=1;
}
if(Time_db_min<10)
{
Time_db=Time_db_hr+":0"+Time_db_min;
}
else
{
Time_db=Time_db_hr+":"+Time_db_min;
}
str2=updated_time_bought;

}
}
//destroy the browser,do necessary updations
p.destroy();
System.out.println("process destroyed");
if(!(str1.equals(guest)))
{
try{
AddTime two=new AddTime();
String sql9="select * from database where Login_Name='"+str1+"';";
System.out.println("in registered");
stmt2=con.createStatement();

result2=stmt2.executeQuery(sql9);
boolean b=result2.next();
System.out.println(sql9);
String TTA=result2.getString("Total_Time_Accessed");
System.out.println(TTA);
String total_time_accessed=two.con(TTA,str2);
sql2="update database set Total_Time_Remaining='00:00',Total_Time_Accessed='"+total_time_accessed+"' where Login_Name='"+str1+"';";
System.out.println(sql2);

stmt4=con.createStatement();
int i=stmt4.executeUpdate(sql2);
}catch(Exception e){System.out.println("HELLO"+e);}
}
sql3="delete welcome where Machine_No='"+str3+"';";
stmt3=con.createStatement();
int i=stmt3.executeUpdate(sql3);
logout.dispose();
new New();
}
}catch (Exception e)
{
System.out.println("Error Executing Notepad: "+e);
}
}
public void run()
{
if(Thread.currentThread()==thread)
{
logout=new Logout(Login_Name);
System.out.println("before function");
p=logout.LogoutFunction(login_time,Time_db);
System.out.println("after function");
thread.stop();
}
}
}

plz do help me.it's a matter of life/death
amit
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"grover_mickey",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: life/death?