本文整理匯總了Java中java.awt.Frame.setLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java Frame.setLocation方法的具體用法?Java Frame.setLocation怎麽用?Java Frame.setLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Frame
的用法示例。
在下文中一共展示了Frame.setLocation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: OverScrollTest
import java.awt.Frame; //導入方法依賴的package包/類
OverScrollTest() {
try {
robot = new Robot();
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage());
}
mainFrame = new Frame();
mainFrame.setSize(400, 200);
mainFrame.setLocation(200, 200);
mainFrame.setLayout(new FlowLayout());
textField = new TextField(10);
textField.setSize(300, 100);
textField.setText("123456 789123");
mainFrame.add(textField);
mainFrame.setVisible(true);
textField.requestFocusInWindow();
}
示例2: createFrame
import java.awt.Frame; //導入方法依賴的package包/類
private static Frame createFrame(String title, int x, int y) {
Frame frame = new Frame();
frame.setSize(200, 200);
frame.setLocation(x, y);
frame.setTitle(title);
frame.setVisible(true);
return frame;
}
示例3: start
import java.awt.Frame; //導入方法依賴的package包/類
public void start() {
//Get things going. Request focus, set size, et cetera
setSize(200, 200);
setVisible(true);
validate();
final Image image = new MultiResolutionCursor();
int center = sizes[0] / 2;
Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
image, new Point(center, center), "multi-resolution cursor");
Frame frame = new Frame("Test Frame");
frame.setSize(300, 300);
frame.setLocation(300, 50);
frame.add(new Label("Move cursor here"));
frame.setCursor(cursor);
frame.setVisible(true);
}
示例4: TextAreaScrolling
import java.awt.Frame; //導入方法依賴的package包/類
TextAreaScrolling() {
try {
robot = new Robot();
} catch (Exception ex) {
throw new RuntimeException("Robot Creation Failed");
}
mainFrame = new Frame();
mainFrame.setSize(200, 200);
mainFrame.setLocation(200, 200);
textArea = new TextArea();
textArea.setText("1234 5678");
textArea.setSelectionStart(3);
textArea.setSelectionEnd(4);
mainFrame.add(textArea);
mainFrame.setVisible(true);
textArea.requestFocusInWindow();
}
示例5: OverScrollTest
import java.awt.Frame; //導入方法依賴的package包/類
OverScrollTest() {
try {
robot = new Robot();
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage());
}
mainFrame = new Frame();
mainFrame.setSize(400, 200);
mainFrame.setLocation(200, 200);
mainFrame.setLayout(new FlowLayout());
textArea = new TextArea(2, 10);
textArea.setSize(300, 100);
textArea.setText("123456 789123");
mainFrame.add(textArea);
mainFrame.setVisible(true);
textArea.requestFocusInWindow();
}
示例6: testChildPropertiesWithFrameAsParent
import java.awt.Frame; //導入方法依賴的package包/類
public void testChildPropertiesWithFrameAsParent() {
parentFrame = new Frame("parent Frame");
parentFrame.setSize(WIDTH, HEIGHT);
parentFrame.setLocation(100, 400);
parentFrame.setBackground(Color.BLUE);
parentLabel = new Label("ParentForegroundAndFont");
parentFont = new Font("Courier New", Font.ITALIC, 15);
parentFrame.setForeground(Color.RED);
parentFrame.setFont(parentFont);
parentFrame.add(parentLabel);
parentFrame.setVisible(true);
frameChildWindow = new Window(parentFrame);
frameChildWindow.setSize(WIDTH, HEIGHT);
frameChildWindow.setLocation(WIDTH + 200, 400);
childLabel = new Label("ChildForegroundAndFont");
frameChildWindow.add(childLabel);
frameChildWindow.setVisible(true);
if (parentFrame.getBackground() == frameChildWindow.getBackground()) {
dispose();
throw new RuntimeException("Child Window Should NOT Inherit "
+ "Parent Frame's Background Color");
}
if (parentDialog.getForeground() == windowChild.getForeground()) {
dispose();
throw new RuntimeException("Child Window Should NOT Inherit "
+ "Parent Frame's Foreground Color");
}
if (parentDialog.getFont() == windowChild.getFont()) {
dispose();
throw new RuntimeException("Child Window Should NOT Inherit "
+ "Parent Frame's Font Color");
}
}
示例7: start
import java.awt.Frame; //導入方法依賴的package包/類
public void start() {
//Get things going. Request focus, set size, et cetera
setSize(200, 200);
setVisible(true);
validate();
final Image image = new BaseMultiResolutionImage(
createResolutionVariant(0),
createResolutionVariant(1),
createResolutionVariant(2),
createResolutionVariant(3)
);
int center = sizes[0] / 2;
Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
image, new Point(center, center), "multi-resolution cursor");
Frame frame = new Frame("Test Frame");
frame.setSize(300, 300);
frame.setLocation(300, 50);
frame.add(new Label("Move cursor here"));
frame.setCursor(cursor);
frame.setVisible(true);
}
示例8: center
import java.awt.Frame; //導入方法依賴的package包/類
/**
* Center {@link Frame} relative to monitor.
*
* @param frame
* the frame
*/
private void center(Frame frame) {
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
frame.setLocation(x, y);
}
示例9: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) throws AWTException
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
// check Robot.mouseMove()
robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
Point mouse = MouseInfo.getPointerInfo().getLocation();
Point point = screen.getLocation();
point.translate(mouseOffset.x, mouseOffset.y);
if (!point.equals(mouse)) {
throw new RuntimeException(getErrorText("Robot.mouseMove", i));
}
// check Robot.getPixelColor()
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(100, 100);
frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
frame.setBackground(color);
frame.setVisible(true);
robot.waitForIdle();
Rectangle bounds = frame.getBounds();
if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
}
// check Robot.createScreenCapture()
BufferedImage image = robot.createScreenCapture(bounds);
int rgb = color.getRGB();
if (image.getRGB(0, 0) != rgb
|| image.getRGB(image.getWidth() - 1, 0) != rgb
|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
|| image.getRGB(0, image.getHeight() - 1) != rgb) {
throw new RuntimeException(
getErrorText("Robot.createScreenCapture", i));
}
frame.dispose();
}
System.out.println("Test PASSED!");
}
示例10: testChildPropertiesWithFrameAsParent
import java.awt.Frame; //導入方法依賴的package包/類
public void testChildPropertiesWithFrameAsParent() {
parentFrame = new Frame("parent Frame");
parentFrame.setSize(WIDTH, HEIGHT);
parentFrame.setLocation(100, 400);
parentFrame.setBackground(Color.BLUE);
parentLabel = new Label("ParentForegroundAndFont");
parentFont = new Font("Courier New", Font.ITALIC, 15);
parentFrame.setForeground(Color.RED);
parentFrame.setFont(parentFont);
parentFrame.add(parentLabel);
parentFrame.setVisible(true);
frameChildDialog = new Dialog(parentFrame, "Frame's child");
frameChildDialog.setSize(WIDTH, HEIGHT);
frameChildDialog.setLocation(WIDTH + 200, 400);
childLabel = new Label("ChildForegroundAndFont");
frameChildDialog.add(childLabel);
frameChildDialog.setVisible(true);
if (parentFrame.getBackground() == frameChildDialog.getBackground()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Frame's Background Color");
}
if (parentFrame.getForeground() == frameChildDialog.getForeground()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Frame's Foreground Color");
}
if (parentFrame.getFont() == frameChildDialog.getFont()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Frame's Font Style/Color");
}
}
示例11: test
import java.awt.Frame; //導入方法依賴的package包/類
private static void test(final Point tmp) throws Exception {
Choice choice = new Choice();
for (int i = 1; i < 7; i++) {
choice.add("Long-long-long-long-long text in the item-" + i);
}
Frame frame = new Frame();
try {
frame.setAlwaysOnTop(true);
frame.setLayout(new FlowLayout());
frame.add(choice);
frame.pack();
frameWidth = frame.getWidth();
frame.setSize(frameWidth, SIZE);
frame.setVisible(true);
frame.setLocation(tmp.x, tmp.y);
openPopup(choice);
} finally {
frame.dispose();
}
}
示例12: getCenteredFrame
import java.awt.Frame; //導入方法依賴的package包/類
public static Frame getCenteredFrame() {
Frame tempframe = new Frame();
tempframe.setSize(0, 0);
Toolkit tool = Toolkit.getDefaultToolkit();
tempframe.setLocation(tool.getScreenSize().width / 2 - 200, tool
.getScreenSize().height / 2 - 150);
tempframe.setTitle("Dialog Box!");
//tempframe.show();
return tempframe;
}
示例13: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
OSInfo.OSType type = OSInfo.getOSType();
if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {
System.out.println("This test is for Solaris and Linux only..." +
"skipping!");
return;
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multi-screen test... skipping!");
return;
}
for (int screen = 0; screen < gds.length; ++screen) {
GraphicsDevice gd = gds[screen];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
Frame frame = new Frame(gc);
frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,
bounds.y + (bounds.height - SIZE) / 2);
frame.setSize(SIZE, SIZE);
frame.setUndecorated(true);
frame.setVisible(true);
// Maximize Frame to reach the struts
frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
Thread.sleep(2000);
Rectangle frameBounds = frame.getBounds();
frame.dispose();
if (bounds.x + insets.left != frameBounds.x
|| bounds.y + insets.top != frameBounds.y
|| bounds.width - insets.right - insets.left != frameBounds.width
|| bounds.height - insets.bottom - insets.top != frameBounds.height) {
throw new RuntimeException("Test FAILED! Wrong screen #" +
screen + " insets: " + insets);
}
}
System.out.println("Test PASSED!");
}
示例14: ComponentIsNotDrawnAfterRemoveAddTest
import java.awt.Frame; //導入方法依賴的package包/類
public ComponentIsNotDrawnAfterRemoveAddTest() {
frame = new Frame("ComponentIsNotDrawnAfterRemoveAddTest");
frame.setSize(500, 500);
frame.setLocation(200, 200);
frame.setLayout(null);
frame.setBackground(Color.RED);
panel = new Panel();
panel.setLayout(null);
panel.setBounds(25, 100, 455, 295);
panel.setBackground(Color.GREEN);
for (int i = 0; i < 10; i++) {
TestCanvas canv1 = new TestCanvas();
canv1.setBounds(i * 45 + 5, 15, 30 + i, 30 + i);
panel.add(canv1);
compList.add(canv1);
TestButton btn1 = new TestButton();
btn1.setBounds(i * 45 + 5, 60, 30 + i, 30 + i);
panel.add(btn1);
compList.add(btn1);
TestCanvas canv2 = new TestCanvas();
canv2.setBounds(i * 45 + 5, 105, 30 + i, 30 + i);
panel.add(canv2);
compList.add(canv2);
TestButton btn2 = new TestButton();
btn2.setBounds(i * 45 + 5, 150, 30 + i, 30 + i);
panel.add(btn2);
compList.add(btn2);
TestCanvas canv3 = new TestCanvas();
canv3.setBounds(i * 45 + 5, 195, 30 + i, 30 + i);
panel.add(canv3);
compList.add(canv3);
TestButton btn3 = new TestButton();
btn3.setBounds(i * 45 + 5, 240, 30 + i, 30 + i);
panel.add(btn3);
compList.add(btn3);
}
frame.add(panel);
frame.setVisible(true);
}
示例15: showRes
import java.awt.Frame; //導入方法依賴的package包/類
private static void showRes(String desc, final BufferedImage src) {
final int w = src.getWidth();
final int h = src.getHeight();
Frame f = new Frame(desc+": dbl-click to exit");
Component c;
f.add(c = new Component() {
public Dimension getPreferredSize() {
return new Dimension(w,h);
}
public void paint(Graphics g) {
g.clearRect(0, 0, getWidth(), getHeight());
g.drawImage(src, 0,0, null);
}
});
c.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
System.exit(0);
}
}
});
f.pack();
synchronized (JPEGsNotAcceleratedTest.class) {
f.setLocation(frameX, frameY);
frameX += f.getWidth();
if ((frameX + f.getWidth()) >
f.getGraphicsConfiguration().getBounds().width)
{
frameY += TEST_H;
if ((frameY + f.getHeight()) >
f.getGraphicsConfiguration().getBounds().height)
{
startY += 30;
startX += 30;
frameY = startY;
}
frameX = startX;
}
};
f.setVisible(true);
}