本文整理汇总了Java中java.awt.Frame.pack方法的典型用法代码示例。如果您正苦于以下问题:Java Frame.pack方法的具体用法?Java Frame.pack怎么用?Java Frame.pack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Frame
的用法示例。
在下文中一共展示了Frame.pack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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) {
final Frame frame = new Frame();
final TextArea ta = new TextArea();
frame.add(ta);
frame.pack();
frame.setVisible(true);
sleep();
final Dimension before = frame.getSize();
frame.pack();
final Dimension after = frame.getSize();
if (!after.equals(before)) {
throw new RuntimeException(
"Expected size: " + before + ", actual size: " + after);
}
frame.dispose();
}
示例3: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
Frame frame = new Frame("Frame Minimize Test");
Button b = new Button("Focus ownder");
frame.add("South", b);
frame.pack();
frame.setVisible(true);
Util.waitForIdle(null);
if (!b.hasFocus()) {
throw new RuntimeException("button is not a focus owner after showing :(");
}
frame.setExtendedState(Frame.ICONIFIED);
Util.waitForIdle(null);
frame.setExtendedState(Frame.NORMAL);
Util.waitForIdle(null);
if (!b.hasFocus()) {
throw new RuntimeException("button is not a focus owner after restoring :(");
}
}
示例4: 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);
}
示例5: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String args[]) {
Frame f = new Frame("DitherTest");
DitherTest ditherTest = new DitherTest();
ditherTest.init();
f.add("Center", ditherTest);
f.pack();
f.setVisible(true);
ditherTest.start();
}
示例6: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
final Frame frame = new Frame("the test");
frame.setLayout(new FlowLayout());
final Button btn1 = new Button("button 1");
frame.add(btn1);
frame.add(new Button("button 2"));
frame.add(new Button("button 3"));
frame.pack();
frame.setVisible(true);
Robot r = Util.createRobot();
Util.waitForIdle(r);
Util.clickOnComp(btn1, r);
Util.waitForIdle(r);
KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
if (kfm.getFocusOwner() != btn1) {
throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
}
EventQueue.invokeAndWait(new Runnable() {
public void run() {
final int n_comps = frame.getComponentCount();
for (int i = 0; i < n_comps; ++i) {
frame.getComponent(i).setVisible(false);
}
}
});
Util.waitForIdle(r);
final Component focus_owner = kfm.getFocusOwner();
if (focus_owner != null && !focus_owner.isVisible()) {
throw new RuntimeException("we have invisible focus owner");
}
System.out.println("test passed");
frame.dispose();
}
示例7: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) {
final DrawXORModeTest c = new DrawXORModeTest();
final Frame f = new Frame("XOR mode test");
f.add(c);
f.pack();
f.setVisible(true);
try {
c.checkResult();
} finally {
f.dispose();
}
}
示例8: 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();
}
示例9: frameTest
import java.awt.Frame; //导入方法依赖的package包/类
private static void frameTest() {
Panel panel =new Panel();
print = new Button("PageDialog");
print.setActionCommand("PageDialog");
print.addActionListener((e) -> {
PrinterJob job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
t.start();
start = true;
PageFormat pf = job.pageDialog(aset);
});
panel.add(print);
frame = new Frame("Test Frame");
frame.setLayout (new BorderLayout ());
frame.add(panel,"South");
frame.pack();
frame.setVisible(true);
t = new Thread (() -> {
if (start) {
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {}
frame.dispose();
}
});
}
示例10: 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();
}
}
示例11: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) {
System.setProperty("sun.java2d.pmoffscreen", "true");
System.setProperty("sun.java2d.ddforcevram", "true");
String name = "red.jpg";
f = new Frame();
f.pack();
if (f.getGraphicsConfiguration().getColorModel().getPixelSize() < 16) {
System.err.println("8-bit display mode detected, dithering issues possible, "+
"considering test passed.");
f.dispose();
return;
}
for (String arg : args) {
if (arg.equals("-write")) {
writeTestImage(name);
System.exit(0);
} else if (arg.equals("-show")) {
showRes = true;
} else if (arg.equals("-low")) {
lowCompression = true;
name ="red_low.jpg";
System.err.println("Using low jpeg compression");
} else if (arg.equals("-help")) {
usage();
} else {
final String filename = arg;
testsStarted++;
new Thread(new Runnable() {
public void run() {
new JPEGsNotAcceleratedTest(filename);
}
}).start();
}
}
if (testsStarted == 0) {
writeTestImage(name);
testsStarted++;
new JPEGsNotAcceleratedTest(name);
}
synchronized (JPEGsNotAcceleratedTest.class) {
while (testsFinished < testsStarted) {
try {
JPEGsNotAcceleratedTest.class.wait(100);
} catch (InterruptedException e) {
failed = true; break;
}
}
}
f.dispose();
if (failed) {
throw new RuntimeException("Test failed");
}
System.err.println("Passed.");
}
示例12: main
import java.awt.Frame; //导入方法依赖的package包/类
public static void main(String[] args) {
boolean show = false;
for (String arg : args) {
if ("-show".equals(arg)) {
show = true;
}
}
String arch = System.getProperty("os.arch");
boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);
DrawImageBilinear test = new DrawImageBilinear();
Frame frame = new Frame();
frame.add(test);
frame.pack();
frame.setVisible(true);
// Wait until the component's been painted
synchronized (test) {
while (!done) {
try {
test.wait();
} catch (InterruptedException e) {
throw new RuntimeException("Failed: Interrupted");
}
}
}
GraphicsConfiguration gc = frame.getGraphicsConfiguration();
if (gc.getColorModel() instanceof IndexColorModel) {
System.out.println("IndexColorModel detected: " +
"test considered PASSED");
frame.dispose();
return;
}
if (!show) {
frame.dispose();
}
if (capture == null) {
throw new RuntimeException("Failed: capture is null");
}
// Test background color
int pixel = capture.getRGB(5, 5);
if (pixel != 0xffffffff) {
throw new RuntimeException("Failed: Incorrect color for " +
"background");
}
// Test pixels
testRegion(capture, new Rectangle(10, 10, 40, 40));
testRegion(capture, new Rectangle(80, 10, 40, 40));
testRegion(capture, new Rectangle(150, 10, 40, 40));
}
示例13: createInstructionUI
import java.awt.Frame; //导入方法依赖的package包/类
private void createInstructionUI() {
mainFrame = new Frame("Drag and drop link from web browser");
layout = new GridBagLayout();
mainControlPanel = new Panel(layout);
resultButtonPanel = new Panel(layout);
GridBagConstraints gbc = new GridBagConstraints();
String instructions
= "INSTRUCTIONS:"
+ "\n 1. Open any browser."
+ "\n 2. Select and drag URL from the browser page and "
+ "drop it on the panel"
+ "\n 3. If test fails, then a popup message will be displayed,"
+ " click Ok and \n click Fail button."
+ "\n 5. Otherwise test passed. Click Pass button.";
instructionTextArea = new TextArea();
instructionTextArea.setText(instructions);
instructionTextArea.setEnabled(false);
instructionTextArea.setBackground(Color.white);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainControlPanel.add(instructionTextArea, gbc);
passButton = new Button("Pass");
passButton.setName("Pass");
passButton.addActionListener(this);
failButton = new Button("Fail");
failButton.setName("Fail");
failButton.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 0;
resultButtonPanel.add(passButton, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
resultButtonPanel.add(failButton, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
mainControlPanel.add(resultButtonPanel, gbc);
mainFrame.add(mainControlPanel);
mainFrame.pack();
mainFrame.setVisible(true);
}
示例14: createInstructionUI
import java.awt.Frame; //导入方法依赖的package包/类
private void createInstructionUI() {
mainFrame = new Frame("Updating TrayIcon Popup Menu Item Test");
layout = new GridBagLayout();
mainControlPanel = new Panel(layout);
resultButtonPanel = new Panel(layout);
GridBagConstraints gbc = new GridBagConstraints();
String instructions
= "INSTRUCTIONS:"
+ "\n 1. Click on the System Tray Icon"
+ "\n 2. Click on any of the displayed Menu items"
+ "\n 3. Repeat step 1 and count the number of items in the "
+ "Menu"
+ "\n 4. The number of items in the Menu should increase by 1"
+ "\n 5. Repeating steps 1, 2 and 3 should not break 4th step"
+ "\n 6. Click Fail if the 4th step is broken, Otherwise "
+ "click Pass ";
instructionTextArea = new TextArea();
instructionTextArea.setText(instructions);
instructionTextArea.setEnabled(false);
instructionTextArea.setBackground(Color.white);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainControlPanel.add(instructionTextArea, gbc);
passButton = new Button("Pass");
passButton.setName("Pass");
passButton.addActionListener(this);
failButton = new Button("Fail");
failButton.setName("Fail");
failButton.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 0;
resultButtonPanel.add(passButton, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
resultButtonPanel.add(failButton, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
mainControlPanel.add(resultButtonPanel, gbc);
mainFrame.add(mainControlPanel);
mainFrame.pack();
mainFrame.setVisible(true);
}
示例15: createInstructionUI
import java.awt.Frame; //导入方法依赖的package包/类
private void createInstructionUI() {
instructionFrame = new Frame("Native Print Dialog and Page Dialog");
layout = new GridBagLayout();
mainControlPanel = new Panel(layout);
resultButtonPanel = new Panel(layout);
GridBagConstraints gbc = new GridBagConstraints();
String instructions
= "\nINSTRUCTIONS:\n"
+ "\n 1. Click on the 'show a native print dialog' button. A "
+ "native print dialog will come up."
+ "\n 2. Click on the 'Cancel' button on Mac OS X or "
+ "'close'(X) on other paltforms. Dialog will be closed."
+ "\n 3. After the dialog is closed another window should "
+ "become the active window."
+ "\n 4. If there no any active window then the test has "
+ "failed. Click on 'Fail' Button."
+ "\n 5. Click on the 'show a native page dialog' button. A "
+ "native page dialog will come up."
+ "\n 6. Click on the 'Cancel' button on Mac OS X or "
+ "'close'(X) on other paltforms. Dialog will be closed."
+ "\n 7. After the dialog is closed another window should "
+ "become the active window."
+ "\n 8. If there no any active window then the test has "
+ "failed. Click on 'Fail' Button."
+ "\n 9. Test Passed. Click on 'Pass' Button.";
instructionTextArea = new TextArea(13, 80);
instructionTextArea.setText(instructions);
instructionTextArea.setEnabled(false);
instructionTextArea.setBackground(Color.white);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0.5;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainControlPanel.add(instructionTextArea, gbc);
passButton = new Button("Pass");
passButton.setName("Pass");
passButton.addActionListener((ActionListener) this);
failButton = new Button("Fail");
failButton.setName("Fail");
failButton.addActionListener((ActionListener) this);
setButtonEnable(false);
gbc.gridx = 0;
gbc.gridy = 0;
resultButtonPanel.add(passButton, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
resultButtonPanel.add(failButton, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
mainControlPanel.add(resultButtonPanel, gbc);
instructionFrame.add(mainControlPanel);
instructionFrame.pack();
instructionFrame.setVisible(true);
}