本文整理汇总了Java中java.awt.Frame.setBounds方法的典型用法代码示例。如果您正苦于以下问题:Java Frame.setBounds方法的具体用法?Java Frame.setBounds怎么用?Java Frame.setBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Frame
的用法示例。
在下文中一共展示了Frame.setBounds方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Frame frame = new Frame();
Robot robot = new Robot();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final GraphicsEnvironment graphicsEnvironment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice graphicsDevice =
graphicsEnvironment.getDefaultScreenDevice();
final Dimension screenSize = toolkit.getScreenSize();
final Insets screenInsets = toolkit.getScreenInsets(
graphicsDevice.getDefaultConfiguration());
final Rectangle availableScreenBounds = new Rectangle(screenSize);
availableScreenBounds.x += screenInsets.left;
availableScreenBounds.y += screenInsets.top;
availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
availableScreenBounds.width, availableScreenBounds.height);
frame.setVisible(true);
robot.waitForIdle();
Rectangle frameBounds = frame.getBounds();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
robot.waitForIdle();
Rectangle maximizedFrameBounds = frame.getBounds();
frame.dispose();
if (maximizedFrameBounds.width < frameBounds.width
|| maximizedFrameBounds.height < frameBounds.height) {
throw new RuntimeException("Maximized frame is smaller than non maximized");
}
}
示例2: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Frame frame = new Frame();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final GraphicsEnvironment graphicsEnvironment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice graphicsDevice =
graphicsEnvironment.getDefaultScreenDevice();
final Dimension screenSize = toolkit.getScreenSize();
final Insets screenInsets = toolkit.getScreenInsets(
graphicsDevice.getDefaultConfiguration());
final Rectangle availableScreenBounds = new Rectangle(screenSize);
availableScreenBounds.x += screenInsets.left;
availableScreenBounds.y += screenInsets.top;
availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
availableScreenBounds.width, availableScreenBounds.height);
frame.setVisible(true);
Rectangle frameBounds = frame.getBounds();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
((SunToolkit) toolkit).realSync();
Rectangle maximizedFrameBounds = frame.getBounds();
if (maximizedFrameBounds.width < frameBounds.width
|| maximizedFrameBounds.height < frameBounds.height) {
throw new RuntimeException("Maximized frame is smaller than non maximized");
}
}
示例3: init
import java.awt.Frame; //导入方法依赖的package包/类
private void init()
{
f = new Frame("Demo");
bt1 = new Button("SIN");
bt2 = new Button("COS");
bt3 = new Button("EXIT");
mc = new MyCanvas();
p = new Panel();
f.setBounds(100, 100, 500, 500);
f.setLayout(new BorderLayout());
p.add(bt1);
p.add(bt2);
p.add(bt3);
f.add(p, BorderLayout.NORTH);
f.add(mc, BorderLayout.CENTER);
addEvent();
f.setVisible(true);
}
示例4: createAWTComponents
import java.awt.Frame; //导入方法依赖的package包/类
private void createAWTComponents() {
Frame f1 = new Frame("F1");
f1.setBounds(100, 300, 100, 100);
f1.setVisible(true);
try {
Thread.sleep(500);
} catch (Exception ex) {
}
f1.setExtendedState(Frame.ICONIFIED);
Frame g1 = new Frame("G1");
g1.setBounds(150, 350, 100, 100);
g1.setVisible(true);
final Dialog d1 = new Dialog((Frame) null, "D1", Dialog.ModalityType.APPLICATION_MODAL);
d1.setBounds(200, 400, 100, 100);
new Thread(new Runnable() {
public void run() {
d1.setVisible(true);
}
}).start();
}
示例5: initTestWindow
import java.awt.Frame; //导入方法依赖的package包/类
public static void initTestWindow() {
mainFrame = new Frame();
p1 = new Panel();
mainFrame.setTitle("TestWindow");
mainFrame.setBounds(700, 10, 400, 100);
tf = new TextField(20);
tf.select(0, 10);
bt = new Button("Disable textfield");
p1.add(tf);
p1.add(bt);
mainFrame.add(p1);
bt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
tf.setEditable(false);
}
});
mainFrame.setVisible(true);
}
示例6: initTestWindow
import java.awt.Frame; //导入方法依赖的package包/类
public static void initTestWindow() {
mainFrame = new Frame();
mainFrame.setTitle("TestWindow");
mainFrame.setBounds(700, 10, 300, 300);
mainFrame.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int ex = e.getModifiersEx();
if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) {
AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set.");
} else {
AltGraphModifierTest.pass();
}
}
});
mainFrame.setVisible(true);
}
示例7: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args)
{
Frame frame1 = new Frame("frame 1");
frame1.setBounds(0, 0, 100, 100);
frame1.setVisible(true);
Util.waitForIdle(null);
Frame frame2 = new Frame("frame 2");
frame2.setBounds(150, 0, 100, 100);
frame2.setVisible(true);
Util.waitForIdle(null);
Frame frame3 = new Frame("frame 3");
final Dialog dialog = new Dialog(frame3, "dialog", true);
dialog.setBounds(300, 0, 100, 100);
EventQueue.invokeLater(new Runnable() {
public void run() {
dialog.setVisible(true);
}
});
try {
EventQueue.invokeAndWait(new Runnable() { public void run() {} });
Util.waitForIdle(null);
EventQueue.invokeAndWait(new Runnable() {
public void run() {
dialog.dispose();
}
});
}
catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
catch (InvocationTargetException ite) {
throw new RuntimeException(ite);
}
frame1.dispose();
frame2.dispose();
frame3.dispose();
}
示例8: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) {
Robot robot = Util.createRobot();
Frame frame = new Frame("Frame");
frame.setBackground(Color.BLUE);
frame.setBounds(200, 50, 300, 300);
frame.setVisible(true);
Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
dialog1.setBackground(Color.RED);
dialog1.setBounds(100, 100, 200, 200);
dialog1.setVisible(true);
Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
dialog2.setBackground(Color.GREEN);
dialog2.setBounds(400, 100, 200, 200);
dialog2.setVisible(true);
Util.waitForIdle(robot);
Util.clickOnComp(dialog2, robot);
Util.waitForIdle(robot);
Point point = dialog1.getLocationOnScreen();
int x = point.x + (int)(dialog1.getWidth() * 0.9);
int y = point.y + (int)(dialog1.getHeight() * 0.9);
try {
if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
throw new RuntimeException("Test FAILED: Dialog is behind the frame");
}
} finally {
frame.dispose();
dialog1.dispose();
dialog2.dispose();
}
}
示例9: initializeGUI
import java.awt.Frame; //导入方法依赖的package包/类
private void initializeGUI() {
frame = new Frame("Test frame");
canvas = new Canvas();
canvas.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) { focusGained = true; }
});
canvas.addKeyListener(this);
frame.setLayout(new BorderLayout());
frame.add(canvas);
frame.setBounds(200, 200, 200, 200);
frame.setVisible(true);
}
示例10: initTestWindow
import java.awt.Frame; //导入方法依赖的package包/类
public static void initTestWindow() {
mainFrame = new Frame("ScrollSelectionTest frame");
mainFrame.setBounds(500, 0, 400, 200);
textField = new TextField(40);
textField.setText("abcdefghijklmnopqrstuvwxyz");
mainFrame.add(textField);
mainFrame.setLayout(new FlowLayout());
textField.select(0, 20);
mainFrame.setVisible(true);
}
示例11: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) {
Frame frame = new Frame("frame");
frame.setBounds(100, 100, 200, 200);
frame.setVisible(true);
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setExtendedState(Frame.ICONIFIED);
if (frame.getExtendedState() != Frame.ICONIFIED) {
frame.dispose();
throw new RuntimeException("Test Failed");
}
frame.dispose();
}
示例12: testFrame
import java.awt.Frame; //导入方法依赖的package包/类
static void testFrame(boolean isUndecorated) throws Exception {
Frame frame = new Frame();
try {
Robot robot = new Robot();
robot.setAutoDelay(100);
frame.setUndecorated(isUndecorated);
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
int x = bounds.x + insets.left;
int y = bounds.y + insets.top;
int width = bounds.width - insets.left - insets.right;
int height = bounds.height - insets.top - insets.bottom;
Rectangle rect = new Rectangle(x, y, width, height);
frame.pack();
frame.setBounds(rect);
frame.setVisible(true);
robot.waitForIdle();
robot.delay(500);
if (frame.getWidth() <= width / 2
|| frame.getHeight() <= height / 2) {
throw new RuntimeException("Frame size is small!");
}
if (!isUndecorated && frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
throw new RuntimeException("Frame state does not equal"
+ " MAXIMIZED_BOTH!");
}
} finally {
frame.dispose();
}
}
示例13: UI
import java.awt.Frame; //导入方法依赖的package包/类
private static void UI() {
Frame frame = new Frame("Test frame");
Choice choice = new Choice();
Stream.of(new String[]{"item 1", "item 2", "item 3"}).forEach(choice::add);
frame.add(choice);
frame.setBounds(100, 100, 400, 200);
frame.setVisible(true);
Font font = choice.getFont();
int size = font.getSize();
int height = choice.getBounds().height;
try {
if (height < size) {
throw new RuntimeException("Test failed");
}
} finally {
frame.dispose();
}
}
示例14: run
import java.awt.Frame; //导入方法依赖的package包/类
public void run() {
frame = new Frame();
final DragSourceListener dragSourceListener = new DragSourceAdapter() {
public void dragDropEnd(DragSourceDropEvent e) {
dropSuccess = e.getDropSuccess();
System.err.println("Drop was successful: " + dropSuccess);
}
};
DragGestureListener dragGestureListener = new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent dge) {
dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
}
};
new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
dragGestureListener);
DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_MOVE);
dtde.dropComplete(true);
System.err.println("Drop");
}
};
new DropTarget(frame, dropTargetListener);
//What would normally go into main() will probably go here.
//Use System.out.println for diagnostic messages that you want
//to read after the test is done.
frame.setUndecorated(true);
frame.setBounds(100, 100, 200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
Robot robot = Util.createRobot();
Util.waitForIdle(robot);
Point startPoint = frame.getLocationOnScreen();
Point endPoint = new Point(startPoint);
startPoint.translate(50, 50);
endPoint.translate(150, 150);
Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);
Util.waitForIdle(robot);
robot.delay(500);
if (dropSuccess) {
System.err.println("test passed");
} else {
throw new RuntimeException("test failed: drop was not successful");
}
}