Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Getting the Dreambot's client Frame (setLocationRelativeTo())


    Cardozz

    Recommended Posts

    Hello there!

     

    I want to setLocationRelativeTo() the dreambot's client for my GUI. Since i can't find anything about the frame in the api or the forums (although i found one topic about it but didnt get me what i wanted), i need to ask you guys.

     

    There are two ways this can work out if somebody can help me:

     

    1. Get the clients' X and Y

    Just getClient().getBaseX() doesn't work, because this will give the actual X value of the client itself, and not referred to your screen.

     

    2. Get the clients' Frame

    By getting the clients' Frame, you can set the gui location relative to it.

     

     

    Any ideas?

    Link to comment
    Share on other sites

    Maybe try this:

    getClient().getInstance().getApplet().getX() & getClient().getInstance().getApplet().getY()
    

    I haven't tested it, but it should be good

    I tried this, but this doesnt seem to work =/

    Link to comment
    Share on other sites

    I did some testing on this.
     
    First, I found out what frames there are when Dreambot has just been started, and I launch FiteLite. Code:

    Frame[] frames = Frame.getFrames();
            Arrays.stream(frames).forEach(frame -> {
                System.out.println("---------------");
                System.out.println(frame);
                System.out.println(frame.getName());
                System.out.println(frame.getTitle());
                System.out.println("---------------");
            });
    

    Result:

    ---------------
    javax.swing.SwingUtilities$SharedOwnerFrame[frame0,0,0,136x39,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal]
    frame0
    
    ---------------
    ---------------
    org.dreambot.1.2.5[frame1,458,181,765x648,invalid,layout=java.awt.BorderLayout,title=DreamBot 2.6.4,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,765x648,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    frame1
    DreamBot 2.6.4
    ---------------
    ---------------
    raptor.view.View[frame2,0,0,716x339,hidden,layout=java.awt.BorderLayout,title=FiteLite,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,8,31,700x300,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    frame2
    FiteLite
    ---------------
    

    So the first 2 frames are candidates to use as our relative location. When I tried it, both worked, and resulted in my GUI being centered above the DreamBot client.

     

    Code:

    pack();
    Frame[] frames = Frame.getFrames();
    setLocationRelativeTo(frames[0]); //0 or 1 both worked
    setVisible(true);
    

    This approach seems fragile, and I don't know enough about Swing to know if that ordering is guaranteed, but it's a start.

    Link to comment
    Share on other sites

    I did some testing on this.

     

    First, I found out what frames there are when Dreambot has just been started, and I launch FiteLite. Code:

    Frame[] frames = Frame.getFrames();
            Arrays.stream(frames).forEach(frame -> {
                System.out.println("---------------");
                System.out.println(frame);
                System.out.println(frame.getName());
                System.out.println(frame.getTitle());
                System.out.println("---------------");
            });
    
    Result:
    ---------------
    javax.swing.SwingUtilities$SharedOwnerFrame[frame0,0,0,136x39,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal]
    frame0
    
    ---------------
    ---------------
    org.dreambot.1.2.5[frame1,458,181,765x648,invalid,layout=java.awt.BorderLayout,title=DreamBot 2.6.4,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,765x648,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    frame1
    DreamBot 2.6.4
    ---------------
    ---------------
    raptor.view.View[frame2,0,0,716x339,hidden,layout=java.awt.BorderLayout,title=FiteLite,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,8,31,700x300,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
    frame2
    FiteLite
    ---------------
    
    So the first 2 frames are candidates to use as our relative location. When I tried it, both worked, and resulted in my GUI being centered above the DreamBot client.

     

    Code:

    pack();
    Frame[] frames = Frame.getFrames();
    setLocationRelativeTo(frames[0]); //0 or 1 both worked
    setVisible(true);
    
    This approach seems fragile, and I don't know enough about Swing to know if that ordering is guaranteed, but it's a start.

    If the one with the correct title works you can just do...

     

    Frame[] frames = Frame.getFrames();
    for(Frame frame : frames) {
        if(frame.getTitle().contains("DreamBot") {
            setLocationRelativeTo(frame); 
            break; 
        }
    }
    
    Link to comment
    Share on other sites

    If the one with the correct title works you can just do...

     

    Frame[] frames = Frame.getFrames();
    for(Frame frame : frames) {
        if(frame.getTitle().contains("DreamBot") {
            setLocationRelativeTo(frame); 
            break; 
        }
    }
    

     

    you could also do

    Frame[] frames = Frame.getFrames();
    int i = 0;
    Frame f;
    while ((f = frames[i++]) != null) {
        if (f.getName().charAt(5) == 0x31) {
          setLocationRelativeTo(f);
          break;
        }
    }
    

    :doge:

    Link to comment
    Share on other sites

    If the one with the correct title works you can just do...

    Frame[] frames = Frame.getFrames();
    for(Frame frame : frames) {
        if(frame.getTitle().contains("DreamBot") {
            setLocationRelativeTo(frame); 
            break; 
        }
    }

    This can break if you title your frame as something that contains "DreamBot" :)

     

    I did some more digging to see if you can rely on the Swing frame:

     

    https://docs.oracle.com/javase/8/docs/api/java/awt/Frame.html#getFrames--

    Warning: this method may return system created frames, such as a shared, hidden frame which is used by Swing. Applications should not assume the existence of these frames, nor should an application assume anything about these frames such as component positions, LayoutManagers or serialization.

    So unfortunately the title solution might be the best option.

    Link to comment
    Share on other sites

    This can break if you title your frame as something that contains "DreamBot" :)

     

    I did some more digging to see if you can rely on the Swing frame:

    So unfortunately the title solution might be the best option.

    According to dream (I blame him if hes wrong :P) our Frame.getFrames() will always return the same three frames in the same order so you can always use your original method.

    Link to comment
    Share on other sites

    According to dream (I blame him if hes wrong :P) our Frame.getFrames() will always return the same three frames in the same order so you can always use your original method.

     

    hey now I said if it gives you the same 2 you could use either one because he said both work.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.