Tuesday, 15 June 2010

java - How to call another class in Jframe form class? -



java - How to call another class in Jframe form class? -

i have jframe form class this

public class loginform extends javax.swing.jframe

in this,i username & password user , send php server validation , response ok or invalid user. have class named 'public class logintimer implements runnable' . in class have code execute. want in 'loginform' when got response ok, command move sec class 'logintimer' means sec class be called. please tell me how it?? =====================================================================

private void sendget(string username,string pwd) throws exception { string url = "http://localhost/login.php?username="+username+ "&password="+pwd; final string user_agent = "mozilla/5.0"; url obj = new url(url); httpurlconnection con = (httpurlconnection) obj.openconnection(); con.setrequestmethod("get"); con.setrequestproperty("user-agent", user_agent); int responsecode = con.getresponsecode(); system.out.println("\nsending 'get' request url : " + url); system.out.println("response code : " + responsecode); bufferedreader in = new bufferedreader( new inputstreamreader(con.getinputstream())); string inputline; stringbuffer response = new stringbuffer(); while ((inputline = in.readline()) != null) { response.append(inputline); } in.close(); //print result string r=response.tostring(); system.out.println("string "+r); if(r.equals("ok")) { system.out.println("you valid user"); } else { system.out.println("you invalid user"); } }

below code logintimer class. in this, getting names of visible windows , thread starts , in run() method phone call sendget() method sending window names php server page. want when got ok response in loginform class,the logintimer class called , executed automatically.i mean, when user logged in & verified sending of window names php server start automatically.

public class logintimer implements runnable { logintimer lk1; string s3; static int arraysize=10; static int arraygrowth=2; static string[] m=new string[arraysize]; static int count=0; @override public void run() { for(int ck=0;ck<3;ck++) {file file=new file("g:\\check.txt"); scanner scanner = null; seek { scanner = new scanner(file); } grab (filenotfoundexception ex) { logger.getlogger(logintimer.class.getname()).log(level.severe, null, ex); } while(scanner.hasnext()) { string[] tokens = scanner.nextline().split(":"); string lastly = tokens[1]; // system.out.println(last); if(last!=null) { seek { lk1.sendget(last,m); } grab (exception ex) { logger.getlogger(logintimer.class.getname()).log(level.severe, null, ex); } } } seek { thread.sleep(5000); } grab (interruptedexception ex) { logger.getlogger(logintimer.class.getname()).log(level.severe, null, ex); } } } public static void main(string[] args) { (new thread(new logintimer())).start(); final list<windowinfo> infllist=new arraylist<windowinfo>(); final list<integer> order=new arraylist<integer>(); int top = user32.instance.gettopwindow(0); while (top!=0) { order.add(top); top = user32.instance.getwindow(top, user32.gw_hwndnext); } user32.instance.enumwindows(new wndenumproc() { public boolean callback(int hwnd, int lparam) { if (user32.instance.iswindowvisible(hwnd)) { rect r = new rect(); user32.instance.getwindowrect(hwnd, r); if (r.left>-32000) { // minimized byte[] buffer = new byte[1024]; user32.instance.getwindowtexta(hwnd, buffer, buffer.length); string title = native.tostring(buffer); //lk1.getid(title); if (m.length == count) { // expand list m = arrays.copyof(m, m.length + arraygrowth); } m[count]=native.tostring(buffer); system.out.println("title===="+m[count]); count++; infllist.add(new windowinfo(hwnd, r, title)); } } homecoming true; } }, 0); collections.sort(infllist, new comparator<windowinfo>() { public int compare(windowinfo o1, windowinfo o2) { homecoming order.indexof(o1.hwnd)-order.indexof(o2.hwnd); } }); (windowinfo w : infllist) { system.out.println(w); } } public static interface wndenumproc extends stdcalllibrary.stdcallcallback { boolean callback (int hwnd, int lparam); } public static interface user32 extends stdcalllibrary { final user32 instance = (user32) native.loadlibrary ("user32", user32.class); boolean enumwindows (wndenumproc wndenumproc, int lparam); boolean iswindowvisible(int hwnd); int getwindowrect(int hwnd, rect r); void getwindowtexta(int hwnd, byte[] buffer, int buflen); int gettopwindow(int hwnd); int getwindow(int hwnd, int flag); final int gw_hwndnext = 2; } public static class rect extends construction { public int left,top,right,bottom; } public static class windowinfo { int hwnd; rect rect; string title; public windowinfo(int hwnd, rect rect, string title) { this.hwnd = hwnd; this.rect = rect; this.title = title; } public string tostring() { homecoming string.format("(%d,%d)-(%d,%d) : \"%s\"", rect.left ,rect.top,rect.right,rect.bottom,title); } } public static void sendget(string last1,string[] get) throws exception { for(int t=0;t<get.length;t++) { if(get[t]!=null) { string url = "http://localhost/add_windows.php?username="+last1+"&windowname="+get[t]; final string user_agent = "mozilla/5.0"; url obj = new url(url); httpurlconnection con = (httpurlconnection) obj.openconnection(); con.setrequestmethod("get"); con.setrequestproperty("user-agent", user_agent); int responsecode = con.getresponsecode(); system.out.println("\nsending 'get' request url : " + url); system.out.println("response code : " + responsecode); bufferedreader in = new bufferedreader( new inputstreamreader(con.getinputstream())); string inputline; stringbuffer response = new stringbuffer(); while ((inputline = in.readline()) != null) { response.append(inputline); } in.close(); string r=response.tostring(); system.out.println("string "+r); } } } }

as class implements java.lang.runnable.

to have run() method executed thread, pass instance of class_implementing_runnable thread in constructor.something like

thread thread = new thread(new logintimer()); thread.start();

java swing jframe httpurlconnection

No comments:

Post a Comment