My Goal:
I am trying to make a program which will log me into my zoom classes at the correct time. I have figured out everything except trying to open zoom, enter the ID and passcode correctly, and logging in to the class.
The Problem:
There is no API which I can use to achieve my goal. There is a certain Zoom API, but it is paid, and I am a minor. The only option I think is left is to make java click and enter text anywhere outside a JFrame.
I tried using java.awt.Robot for this, but it can only click on a button inside the JFrame. I tried overlapping the two buttons and keeping the zoom window focused, but Java changes the focus to the JFrame.
If there is any other alternative in Java, or if there is any other external Library or API that may come in use, please suggest me the same.
Thank you in advance.
I tried using java.awt.Robot for this, but it can only click on a button inside the JFrame.
The Robot can be used to generate an OS level event.
If you want the Robot to click out side the frame then you need to move the mouse outside the bounds of the frame.
Simple example:
public static void main(String[] args) throws Exception
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setLocation(25, 25);
frame.setSize(100, 100);
frame.setVisible(true);
Robot robot = new Robot();
robot.delay(2000);
robot.mouseMove(15, 15 );
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
The Robot will click the system menu of the window found at the top/left corner of your desktop. So make sure you have a window maximized.
You could use WindowListener,#windowDeactivated or WindowFocusListener#windowLostFocus, but you have to be careful with owned JDialog's (as you have to be with FocusListener anyway)
Related
I'm using at the moment the Robot class of the AWT library for a Java Frame.
But when I minimize the frame, the robot will still type and using the mouse in another application that isn't even written in Java.
How can I set the focus on the frame only and when I minimize, it'll still continue?
How can I set the focus on the frame only and when I minimize, it'll still continue?
You can't. By design a minimized frame does not have, and cannot get, focus.
You might be able to 'hack it' by making the frame go almost transparent when asked to minimize, though that will block input to any window that is behind it, and will fail if another is in front.
That's the whole point of Robot. It would be a lot less useful if it could only affect Java programs. – Kayaman May 12 '15 at 6:06
That's right. Robot only 'controls', you need to provide logic like 'If Frame minimized, click the minimized icon' to the Robot.
But this involves a whole set of new questions:
How do you know the Frame is minimized? (Sikuli)
What is the coordinate for the minimized icon? (Sikuli)
After you at least answered these two questions, you can control the Robot to have your Frame back and continue with your GUI Automation.
The answers are in the brackets.
JFrame with hidden or no maximize button but should be able to re-size using mouse(clicking and dragging on jFrame border). setResizable(false) is only disabling the minimize button but not able to re-size using mouse.
I personally can't think of a reason to allow resize and not allow maximize but here is an example of how to prevent maximizing a JFrame while still allowing resize and minimize. Tested in windows, untested on all other platforms. Full screen flash is minimized using setMaximizedBounds().
final JFrame jFrameNoMax = new JFrame() {
{
setMaximizedBounds(new Rectangle(0, 0));
addWindowStateListener(new WindowStateListener() {
public void windowStateChanged(final WindowEvent e) {
if (e.getNewState() == MAXIMIZED_BOTH) {
setExtendedState(NORMAL);
}
}
});
}
};
// Tester
jFrameNoMax.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
jFrameNoMax.setSize(300, 300);
jFrameNoMax.setLocation(300, 300);
jFrameNoMax.setVisible(true);
You can take the following steps:
-Right click on JFrame
-Select properties
-Uncheck the resizable checkbox
-Close properties
-Run the program
See the attached illustration:
One option could be to use a JDialog instead of a JFrame. This allows the window to be manually resizeable but not maximizeable. The only problem with doing this is that you lose both the minimize and maximize buttons. This may or may not be a problem for your application.
To be honest, I didn't quite know how to express my question in the title. So if someone has a clearer idea of what i'm trying to ask, then please be so kind as to edit it, for the greater good of mankind.
I have the following code:
public class Main {
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
JFrame frame = new JFrame();
Window window = new Window(frame);
JButton btn = new JButton("Quit");
window.add(btn);
if(gd.isFullScreenSupported())
gd.setFullScreenWindow(window);
btn.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
gd.setFullScreenWindow(null);
}
});
}
}
What I want to do is make a library system, illustrated in full screen mode. Inside the full screen mode, there should be simple frame windows with text fields in them and so on... No heavy 2D/3D graphics required here...
My problem is, the quit button is resized to fit the entire screen. I've tried to use setBounds, setSize, etc, on the frame, window and even button... But it doesn't seem to let me be able to center the button in the middle.
So my question: Is it possible to make JFrame application windows inside a JFrame application window which is set to full screen exclusive mode? Or is it only possible to use full screen exclusive mode together with 2D/3D methods like drawing?
Note: The only thing I intend to use full screen mode for is to set it to a black background, and have a Jframe window ontop of this black background in the center of the application. It is to give the illusion that the application is actually a system.
Thank you.
P.S. please note that the quit button was merely for my own testing purposes. It won't be part of the actual system, so my question does not revolve around how to resize this particular quit button.
Fullscreen Exclusive Mode is not meant to have Swing components inside. It is meant as a high performance way to draw graphics in Java (and can benefit as much as possible of underlaying hardware if done right).
What you want to do could be done by using an undecorated JDesktopPane and maximize it over the dimensions of the screen. Then proceed with using a JInternalFrame to have a JFrame like window inside that JDesktopPane.
I've included links to the respective API sections, they should get you started.
I think that what you are after is an MDI Application. If that is what you are after you could take a look here.
Your problem is that you do not use layout manager correctly.
Learn about layout managers - the modules that put and size/resize the visual components on screen. Then decide how do you want your button to look like and then decide which layout manager to use. It will do its job.
You know what i also had the exact same problem and the only thing i know from my experience is that you can use jinternal frame and set its property undecorated to true then add your custom title bar according to your requirement.
How can I block input from keyboard and mouse when my Java application is running.
Like we block input in AutoIt with BlockInput(1) , I also want to do same in Java.
I can only answer for a swing application. For your main frame you should have this
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
//or if you are using awt
Frame frame = new Frame();
frame.addWindowListener(new WindowAdapter() {
// handle the window closing event here
});
You can try This - JNativeHook, a global keyboard & mouse listener library for Java.
Create insance of transparent window (Window, not Frame or JFrame) and put it exactly on your application's window. User will not see anything (because it is transparent). But mouse and keyboard events will arrive to this transparent window.
Tip: the window should not be 100% transparent. In this case this trick does not work. put opacity 0.01.
Can I disable the minimize button in JFrame?
I have already tried setUndecorated() and setResizable() but both did not work.
I'm trying to add images to a panel at a random location (which works) but when the JFrame is minimized by clicking at the minimize button (not when frame minimizes by clicking the background window) images assemble at the top in a row.
Can someone help?
Thanks!
If you also want to disable the maximize button then you can use a JDialog instead of a JFrame... as far as I know you cannot disable the minimize button in a JFrame. JDialog only has a close button. Hope this helps
i m trying to add imags to a panel at
a random location which i m able to
do) bt wen frame is minimized by
clicking at the minimize button (not
wen frame minimizes by clicking at the
background window) images assemble at
the top in a row.
Well, it sounds like you are adding labels to a panel and using the setLocation() method to position the labels.
The problem is that by default a JPanel uses a FlowLayout so whenever you do anything to the frame like minimize, maximize, iconify or resize the frame the layout manger is invoked and the labels are arranged according the the rules of the layout manager.
If your requirement is to have random positioning, then you need to use a "null layout".
Read the section from the Swing tutorial that explains how Absolute Positioning works for more information and a working example.
Use JDialog instead of JFrame it has only the Close button on the top.