Advertisement
FALSkills

Untitled

Mar 12th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public static JFrame findTRiBotFrame(){
  2. for(Frame frame:JFrame.getFrames()){
  3. if(frame.getTitle().contains("TRiBot Old-School")){
  4. return (JFrame) frame;
  5. }
  6. }
  7. return null;
  8. }
  9.  
  10. public static List<Component> getAllComponents(final Container c) {
  11. Component[] comps = c.getComponents();
  12. List<Component> compList = new ArrayList<Component>();
  13. for (Component comp : comps) {
  14. compList.add(comp);
  15. if (comp instanceof Container)
  16. compList.addAll(getAllComponents((Container) comp));
  17. }
  18. return compList;
  19. }
  20.  
  21. public static void pressJMenuButton(String button){
  22. JMenuBar bar = null;
  23. for(Frame frame:JFrame.getFrames()){
  24. if(frame.getTitle().contains("TRiBot Old-School")){
  25. frame = (JFrame) frame;
  26. List<Component> list = getAllComponents(frame);
  27. for(Component c:list){
  28. if(c.getClass().equals(javax.swing.JMenuBar.class)){
  29. bar = (JMenuBar) c;
  30. break;
  31. }
  32. }
  33. break;
  34. }
  35. }
  36. for(int i=0;i<bar.getMenuCount();i++){
  37. JMenu menu = bar.getMenu(i);
  38. if(menu == null)
  39. continue;
  40. for(int j=0;j<bar.getMenu(i).getItemCount();j++){
  41. JMenuItem item = menu.getItem(j);
  42. if(item != null){
  43. String command = item.getActionCommand();
  44. if(command != null && command.equals(button)){
  45. item.doClick();
  46. return;
  47. }
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement