Cardozz 46 Share Posted July 10, 2016 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 More sharing options...
Pandemic 2703 Share Posted July 10, 2016 Maybe try this: getClient().getInstance().getApplet().getX() & getClient().getInstance().getApplet().getY() I haven't tested it, but it should be good Link to comment Share on other sites More sharing options...
Cardozz 46 Author Share Posted July 10, 2016 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 More sharing options...
Hopewelljnj 46 Share Posted July 10, 2016 I thought it was Frame.getFrame() If not it's Instance. getInstance() not getClient().getInstance() Link to comment Share on other sites More sharing options...
raptor 10 Share Posted July 11, 2016 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 More sharing options...
Hopewelljnj 46 Share Posted July 11, 2016 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 More sharing options...
Dreamlicker 750 Share Posted July 12, 2016 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; } } Link to comment Share on other sites More sharing options...
raptor 10 Share Posted July 12, 2016 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 More sharing options...
Hopewelljnj 46 Share Posted July 12, 2016 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 ) 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 More sharing options...
Dreamlicker 750 Share Posted July 12, 2016 According to dream (I blame him if hes wrong ) 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.