Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static JFrame findTRiBotFrame(){
- for(Frame frame:JFrame.getFrames()){
- if(frame.getTitle().contains("TRiBot Old-School")){
- return (JFrame) frame;
- }
- }
- return null;
- }
- public static List<Component> getAllComponents(final Container c) {
- Component[] comps = c.getComponents();
- List<Component> compList = new ArrayList<Component>();
- for (Component comp : comps) {
- compList.add(comp);
- if (comp instanceof Container)
- compList.addAll(getAllComponents((Container) comp));
- }
- return compList;
- }
- public static void pressJMenuButton(String button){
- JMenuBar bar = null;
- for(Frame frame:JFrame.getFrames()){
- if(frame.getTitle().contains("TRiBot Old-School")){
- frame = (JFrame) frame;
- List<Component> list = getAllComponents(frame);
- for(Component c:list){
- if(c.getClass().equals(javax.swing.JMenuBar.class)){
- bar = (JMenuBar) c;
- break;
- }
- }
- break;
- }
- }
- for(int i=0;i<bar.getMenuCount();i++){
- JMenu menu = bar.getMenu(i);
- if(menu == null)
- continue;
- for(int j=0;j<bar.getMenu(i).getItemCount();j++){
- JMenuItem item = menu.getItem(j);
- if(item != null){
- String command = item.getActionCommand();
- if(command != null && command.equals(button)){
- item.doClick();
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement