When I try to invoke frame2 from frame1What does invoke frame2 mean? You invoke a method, not a class. Which method of frame2's class are you invoking, and what do you expect it to perform?
the focus is shifting to frame1 instead of frame2What do you mean by "shifting to frame1"? Is it on frame2 initially? Is it on frame1, but on another widget within frame1?
though I am doing setVisible(true) on frame2.From the Javadoc http://docs.oracle.com/javase/6/docs/api/java/awt/Window.html#setVisible%28boolean%29, if a frame/window is initially invisible, setVisible(true) only displays it, but nothing says it should give it the focus. A second call to setVisible(true) would bring the window/frame to front, i.e. give it the focus.
This behavior is not consistent.Not consistent with what? Do you have other examples where setVisible() gives the focus differently than in this example? Does frame2 call frame1.setVisible(...) and result in a different effect?