本文整理匯總了Java中java.awt.Frame.setLocationRelativeTo方法的典型用法代碼示例。如果您正苦於以下問題:Java Frame.setLocationRelativeTo方法的具體用法?Java Frame.setLocationRelativeTo怎麽用?Java Frame.setLocationRelativeTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Frame
的用法示例。
在下文中一共展示了Frame.setLocationRelativeTo方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
final Dimension expected = new Dimension(300, 300);
final Frame frame = new Frame();
final ScrollPane sp = new ScrollPane();
sp.setSize(expected);
frame.add(sp);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
sleep();
final Dimension size = frame.getSize();
if (size.width < expected.width || size.height < expected.height) {
throw new RuntimeException(
"Expected size: >= " + expected + ", actual size: " + size);
}
frame.dispose();
}
示例2: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
for (int i = 0; i < 10; ++i) {
final Frame frame = new Frame();
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
ListRepaint list = new ListRepaint();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.select(0);
frame.add(list);
frame.setVisible(true);
sleep();
list.test();
frame.dispose();
}
}
示例3: Unit
import java.awt.Frame; //導入方法依賴的package包/類
public Unit(){
getBestSize();
net = new Net(new int[]{4,5,4}, true);
graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");
frame = new Frame();
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
canvas.addKeyListener(new InputHandler());
canvas.addMouseListener(new InputHandler());
canvas.addMouseMotionListener(new InputHandler());
frame.add(canvas);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
Test.quit(net);
}
});
frame.setVisible(true);
gc = canvas.getGraphicsConfiguration();
vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);
}
示例4: Unit
import java.awt.Frame; //導入方法依賴的package包/類
public Unit(){
getBestSize();
net = new Net(new int[]{2,5,2});
graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");
frame = new Frame();
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
canvas.addKeyListener(new InputHandler());
canvas.addMouseListener(new InputHandler());
canvas.addMouseMotionListener(new InputHandler());
frame.add(canvas);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
Test.quit(net);
}
});
frame.setVisible(true);
gc = canvas.getGraphicsConfiguration();
vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);
}
示例5: createAndShowGUI
import java.awt.Frame; //導入方法依賴的package包/類
private static void createAndShowGUI() {
frame = new Frame();
frame.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 0));
frame.setSize(600, 600);
frame.setLocationRelativeTo(null);
for (int i = 1; i < 10001; ++i) {
frame.add(new JButton("Button " + i));
}
frame.setVisible(true);
}
示例6: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
final Frame frame = new Frame();
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
for (int i = 0; i < 1000; ++i) {
frame.setSize(100, 100);
frame.setSize(200, 200);
frame.setSize(300, 300);
}
frame.dispose();
}
示例7: SharedMemoryPixmapsTest
import java.awt.Frame; //導入方法依賴的package包/類
/** Creates a new instance of SharedMemoryPixmapsTest */
public SharedMemoryPixmapsTest() {
testFrame = new Frame("SharedMemoryPixmapsTest");
testFrame.add(new TestComponent());
testFrame.setUndecorated(true);
testFrame.setResizable(false);
testFrame.pack();
testFrame.setLocationRelativeTo(null);
testFrame.setVisible(true);
testFrame.toFront();
}
示例8: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
for (int i = 0; i < 10; ++i) {
final Frame frame = new Frame();
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
LabelRepaint label = new LabelRepaint();
frame.add(label);
frame.setVisible(true);
sleep();
label.test();
frame.dispose();
}
}
示例9: run
import java.awt.Frame; //導入方法依賴的package包/類
@Override
public void run() {
contextToDispose = SunToolkit.createNewAppContext();
Frame f = new Frame();
f.setSize(300, 300);
f.setLocationRelativeTo(null);
f.setVisible(true);
thread = new Thread(() -> {
while(true);
});
thread.start();
sync();
}
示例10: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) throws AWTException {
ExtendedRobot robot = new ExtendedRobot();
robot.setAutoDelay(50);
final Frame frame = new Frame();
final Component label = new PaintNativeOnUpdate();
frame.setBackground(Color.RED);
frame.add(label);
frame.setSize(300, 300);
frame.setUndecorated(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
robot.waitForIdle(1000);
label.repaint();// first paint
robot.waitForIdle(1000);
label.repaint();// incremental paint
robot.waitForIdle(1000);
Point point = label.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
point.y + label.getHeight() / 2);
if (!color.equals(Color.GREEN)) {
System.err.println("Expected color = " + Color.GREEN);
System.err.println("Actual color = " + color);
throw new RuntimeException();
}
frame.dispose();
}
示例11: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) {
Robot robot = Util.createRobot();
Frame testFrame = new Frame("Test Frame");
testFrame.setSize(200, 200);
testFrame.addWindowStateListener(new WindowStateListener() {
@Override
public void windowStateChanged(WindowEvent e) {
listenerNotified.set(true);
synchronized (listenerNotified) {
listenerNotified.notifyAll();
}
}
});
testFrame.setVisible(true);
Frame mainFrame = new Frame("Main Frame");
mainFrame.setSize(200, 200);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
Util.waitForIdle(robot);
try {
Util.clickOnComp(mainFrame, robot);
Util.waitForIdle(robot);
// NORMAL -> ICONIFIED
listenerNotified.set(false);
testFrame.setExtendedState(Frame.ICONIFIED);
Util.waitForIdle(robot);
Util.waitForCondition(listenerNotified, 2000);
if (!listenerNotified.get()) {
throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +
"ICONIFIED transition");
}
if (testFrame.getExtendedState() != Frame.ICONIFIED) {
throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");
}
// ICONIFIED -> NORMAL
listenerNotified.set(false);
testFrame.setExtendedState(Frame.NORMAL);
Util.waitForIdle(robot);
Util.waitForCondition(listenerNotified, 2000);
if (!listenerNotified.get()) {
throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +
"NORMAL transition");
}
if (testFrame.getExtendedState() != Frame.NORMAL) {
throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");
}
} finally {
testFrame.dispose();
mainFrame.dispose();
}
}
示例12: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) throws AWTException {
robot = new Robot();
Frame bigOne = new Frame();
bigOne.setSize(200, 200);
bigOne.setLocationRelativeTo(null);
bigOne.setVisible(true);
Frame f = new Frame();
f.setLayout(new BorderLayout());
f.setSize(120, 150);
f.setLocationRelativeTo(null);
Canvas c = new MyCanvas();
f.add(c, BorderLayout.CENTER);
c.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
switch(state) {
case 0: // the first event should be (0,0)
if (e.getX() != 0 || e.getY() != 0) {
System.out.println("state 0: wrong location" + e);
break;
}
state++;
break;
case 1: // the second event should be (1,1)
if (e.getX() != 1 || e.getY() != 1) {
System.out.println("state 1: wrong location " + e);
break;
}
state++;
break;
case 2: // this should never happen
System.out.println("state 2: wrong location " + e);
}
}
});
f.pack();
f.setVisible(true);
bigPause();
Point p = c.getLocationOnScreen();
doPress(p);
p.x += 1;
p.y += 1;
doPress(p);
p.x -= 2;
p.y -= 2;
doPress(p);
bigPause();
f.dispose();
bigOne.dispose();
// ...and at the end the state should be 2
if (state != 2) {
throw new RuntimeException("wrong state: " + state);
}
}
示例13: 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");
}
}