当前位置: 技术问答>java相关
如何让jframe最大化?
来源: 互联网 发布时间:2015-01-12
本文导语: 要让窗口右上角的图标也成为最大化图标,不只是将jframe的大小设成最大。 | 这是bootcool写的代码,我贴出来给你看看,呵呵,我就是看了bootcool的代码才实现的. //看看这。 import java.awt.*; import ja...
要让窗口右上角的图标也成为最大化图标,不只是将jframe的大小设成最大。
|
这是bootcool写的代码,我贴出来给你看看,呵呵,我就是看了bootcool的代码才实现的.
//看看这。
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 MaxFrame extends JFrame {
JButton button = new JButton("hit me");
public MaxFrame(){
getContentPane().add(button);
setVisible(true);
setSize(100,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
// create a robot to feed in GUI events
Robot rob = new Robot();
// move cursor to the top, left corner
Point p = 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);
}
catch (Exception exc) {
System.err.println(exc);
}
}
});
}
public static void main(String args[]){
MaxFrame f = new MaxFrame();
f.show();
}
}
//看看这。
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 MaxFrame extends JFrame {
JButton button = new JButton("hit me");
public MaxFrame(){
getContentPane().add(button);
setVisible(true);
setSize(100,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
// create a robot to feed in GUI events
Robot rob = new Robot();
// move cursor to the top, left corner
Point p = 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);
}
catch (Exception exc) {
System.err.println(exc);
}
}
});
}
public static void main(String args[]){
MaxFrame f = new MaxFrame();
f.show();
}
}