当前位置: 技术问答>java相关
如何使JFrame最大化?
来源: 互联网 发布时间:2015-01-30
本文导语: 据说只能通过Robot来实现,现在问题就出来了,我想知道还有没有别的方式来实现(用Toolkit获得窗口大小就免了),还有,谁能提供一点robot的例子给我看一下(查api没看明白)? | //看看这...
据说只能通过Robot来实现,现在问题就出来了,我想知道还有没有别的方式来实现(用Toolkit获得窗口大小就免了),还有,谁能提供一点robot的例子给我看一下(查api没看明白)?
|
//看看这。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RobotDemo {
public static void main(String args[]) throws AWTException {
JFrame frame = new JFrame("RobotDemo");
frame.setSize(200, 150);
frame.setLocation(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// create a robot to feed in GUI events
Robot rob = new Robot();
// move cursor to the top, left corner
Point p = frame.getLocationOnScreen();
rob.mouseMove(p.x + 5, p.y + 5);
// press and release left mouse button
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);
// send an 'x' key press
rob.keyPress(KeyEvent.VK_X);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RobotDemo {
public static void main(String args[]) throws AWTException {
JFrame frame = new JFrame("RobotDemo");
frame.setSize(200, 150);
frame.setLocation(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// create a robot to feed in GUI events
Robot rob = new Robot();
// move cursor to the top, left corner
Point p = frame.getLocationOnScreen();
rob.mouseMove(p.x + 5, p.y + 5);
// press and release left mouse button
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);
// send an 'x' key press
rob.keyPress(KeyEvent.VK_X);
}
}
|
using:
public synchronized void setState(int state)
public synchronized void setState(int state)