如何在Jframe表单类中调用另一个类?

Java刷新器

我有一个这样的Jframe表单类

  public class LoginForm extends javax.swing.JFrame 

在这种情况下,我从用户那里获取用户名和密码,然后将其发送到php服务器进行验证,并将获得“确定”或“无效用户”的响应。我还有一个名为“公共类LoginTimer实现Runnable”的类在这个课上,我有一些代码要执行。我希望在“ LoginForm ”中得到正确的响应后,控件将移至第二类“ LoginTimer ”,这意味着将
调用第二类请告诉我该怎么做?
================================================== ===================

 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 to 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 are a valid user");

      }
      else
      {
          System.out.println("You are an invalid user");
      }


 }

下面是我的LoginTimer类的代码在这种情况下,我获取可见窗口的名称,然后启动线程,并在run()方法中调用sendGet()方法,以将窗口名称发送到php服务器页面。我希望当我在LoginForm类中获得OK响应时LoginTimer类将被自动调用并执行。我的意思是,当用户登录并验证后,将自动开始向php服务器发送窗口名称。

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;
      try
      {
         scanner = new Scanner(file);
      }
      catch (FileNotFoundException ex)
      {
         Logger.getLogger(LoginTimer.class.getName()).log(Level.SEVERE, null, ex);
      }

      while(scanner.hasNext())
      {
       String[] tokens = scanner.nextLine().split(":");
       String last = tokens[1];
      // System.out.println(last);
        if(last!=null)
        {
           try 
           {
              lk1.sendGet(last,m);

           }
           catch (Exception ex) 
           {
              Logger.getLogger(LoginTimer.class.getName()).log(Level.SEVERE, null, ex);
           }
        }
      } 
        try {
            Thread.sleep(5000);
        } catch (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));
        }

       }
       return true;
    }
    }, 0);

 Collections.sort(inflList, new Comparator<WindowInfo>()
 {
    public int compare(WindowInfo o1, WindowInfo o2)
    {
    return order.indexOf(o1.hwnd)-order.indexOf(o2.hwnd);
    }
 });
  for (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 Structure 
 {
    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()
    {
     return 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 to 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);
      }
     }


 }

}
SparkOn

当您的类实现java.lang.Runnable时。

要让run()方法由线程执行,请将class_implementing_Runnable的实例传递给其构造函数中的Thread。

Thread thread = new Thread(new LoginTimer());
   thread.start();

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在另一个类中调用一个类的main()方法?

来自分类Dev

如何从另一个类调用表单?

来自分类Dev

如何在类中调用函数以在php中调用另一个类?

来自分类Dev

如何在我的主类的另一个类中调用方法?

来自分类Dev

如何在另一个类中获取JFrame对象运动

来自分类Dev

如何在另一个类中使用JFrame中的值

来自分类Dev

如何在Java中扩展2个类?我需要扩展JFrame和另一个类

来自分类Dev

从另一个类调用JFrame上的绘图

来自分类Dev

如何在JavaScript中从另一个类中调用一个类?(初学者的问题)

来自分类Dev

您如何在一个类中从另一个类中调用方法?

来自分类Dev

如何在另一个文件类中调用一个类及其功能

来自分类Dev

如何在Selenium WebDriver中从一个类到另一个类调用Web元素

来自分类Dev

如何在同一个类的另一个方法中调用一个方法?

来自分类Dev

如何在一个类中从另一个调用一个函数(方法)?

来自分类Dev

如何从另一个类中迅速调用另一个方法?

来自分类Dev

从另一个类调用另一个JFrame / JPanel

来自分类Dev

如何在python中从另一个类调用函数?

来自分类Dev

如何在Matlab的另一个m文件中调用类的成员函数?

来自分类Dev

如何在另一个类中调用列表对象

来自分类Dev

如何在另一个文件中调用类?

来自分类Dev

如何在另一个文件中调用类?

来自分类Dev

如何在Kivy语言的另一个类中调用函数?

来自分类Dev

如何在python中从另一个类调用函数

来自分类Dev

如何在按钮单击事件中从另一个类调用方法?

来自分类Dev

如何在另一个类中调用抽象的内部类方法?

来自分类Dev

如何在Java中从另一个类调用方法?

来自分类Dev

PYQT 4:如何在另一个类中调用GUI函数?

来自分类Dev

如何在另一个类中调用函数

来自分类Dev

HaxeFlixel:如何在另一个类中调用getter / setter变量

Related 相关文章

  1. 1

    如何在另一个类中调用一个类的main()方法?

  2. 2

    如何从另一个类调用表单?

  3. 3

    如何在类中调用函数以在php中调用另一个类?

  4. 4

    如何在我的主类的另一个类中调用方法?

  5. 5

    如何在另一个类中获取JFrame对象运动

  6. 6

    如何在另一个类中使用JFrame中的值

  7. 7

    如何在Java中扩展2个类?我需要扩展JFrame和另一个类

  8. 8

    从另一个类调用JFrame上的绘图

  9. 9

    如何在JavaScript中从另一个类中调用一个类?(初学者的问题)

  10. 10

    您如何在一个类中从另一个类中调用方法?

  11. 11

    如何在另一个文件类中调用一个类及其功能

  12. 12

    如何在Selenium WebDriver中从一个类到另一个类调用Web元素

  13. 13

    如何在同一个类的另一个方法中调用一个方法?

  14. 14

    如何在一个类中从另一个调用一个函数(方法)?

  15. 15

    如何从另一个类中迅速调用另一个方法?

  16. 16

    从另一个类调用另一个JFrame / JPanel

  17. 17

    如何在python中从另一个类调用函数?

  18. 18

    如何在Matlab的另一个m文件中调用类的成员函数?

  19. 19

    如何在另一个类中调用列表对象

  20. 20

    如何在另一个文件中调用类?

  21. 21

    如何在另一个文件中调用类?

  22. 22

    如何在Kivy语言的另一个类中调用函数?

  23. 23

    如何在python中从另一个类调用函数

  24. 24

    如何在按钮单击事件中从另一个类调用方法?

  25. 25

    如何在另一个类中调用抽象的内部类方法?

  26. 26

    如何在Java中从另一个类调用方法?

  27. 27

    PYQT 4:如何在另一个类中调用GUI函数?

  28. 28

    如何在另一个类中调用函数

  29. 29

    HaxeFlixel:如何在另一个类中调用getter / setter变量

热门标签

归档