use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class VSyncedBufferStrategyTest method createAndShowDescGUI.
private static void createAndShowDescGUI(final Frame f3, final Frame f1, final Frame f2) throws HeadlessException, RuntimeException {
final JFrame desc = new JFrame("VSyncedBufferStrategyTest - Description");
desc.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
f1.dispose();
f2.dispose();
f3.dispose();
l.countDown();
}
});
JPanel p = new JPanel();
JButton bPassed = new JButton("Passed");
bPassed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
desc.dispose();
f1.dispose();
f2.dispose();
f3.dispose();
l.countDown();
}
});
JButton bFailed = new JButton("Failed");
bFailed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
failed = true;
desc.dispose();
f1.dispose();
f2.dispose();
f3.dispose();
l.countDown();
}
});
p.setLayout(new FlowLayout());
p.add(bPassed);
p.add(bFailed);
JTextArea ta = new JTextArea(24, 75);
ta.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
ta.setEditable(false);
ta.setText(description);
desc.add("Center", new JScrollPane(ta));
desc.add("South", p);
desc.pack();
desc.setLocation(BLOCK_W * 10 + 50, 0);
desc.setVisible(true);
}
use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class OnScreenRenderingResizeTest method main.
public static void main(String[] args) {
for (String arg : args) {
if ("-inf".equals(arg)) {
System.err.println("Test will run indefinitely");
RUN_TIME = Long.MAX_VALUE;
} else if ("-nocheck".equals(arg)) {
System.err.println("Test will not check rendering results");
nocheck = true;
} else {
System.err.println("Usage: OnScreenRenderingResizeTest [-inf][-nocheck]");
}
}
BufferedImage output = new BufferedImage(IMAGE_W, IMAGE_H, BufferedImage.TYPE_INT_RGB);
output.setAccelerationPriority(0.0f);
Graphics g = output.getGraphics();
g.setColor(renderColor);
g.fillRect(0, 0, output.getWidth(), output.getHeight());
final Frame frame = new Frame("OnScreenRenderingResizeTest") {
public void paint(Graphics g) {
}
public void update(Graphics g) {
}
};
frame.setBackground(bgColor);
frame.setUndecorated(true);
frame.pack();
GraphicsConfiguration gc = frame.getGraphicsConfiguration();
Rectangle gcBounds = gc.getBounds();
frame.setBounds(gcBounds.width / 4, gcBounds.height / 4, FRAME_W, FRAME_H);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
done = true;
}
});
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
frame.setVisible(true);
}
});
// wait for Vista's effects to complete
Thread.sleep(2000);
} catch (Exception ex) {
ex.printStackTrace();
}
int maxW = gcBounds.width / 2;
int maxH = gcBounds.height / 2;
int minW = frame.getWidth();
int minH = frame.getHeight();
int incW = 10, incH = 10, cnt = 0;
Robot robot = null;
if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
try {
robot = new Robot();
} catch (AWTException ex) {
System.err.println("Robot creation failed, continuing.");
}
} else {
System.err.println("No screen rendering checks.");
}
VolatileImage vi = gc.createCompatibleVolatileImage(512, 512);
vi.validate(gc);
long timeStarted = System.currentTimeMillis();
while (!done && (System.currentTimeMillis() - timeStarted) < RUN_TIME) {
if (++cnt > 100) {
int w = frame.getWidth() + incW;
int h = frame.getHeight() + incH;
if (w < minW || w > maxW) {
incW = -incW;
}
if (h < minH || h > maxH) {
incH = -incH;
}
frame.setSize(w, h);
cnt = 0;
}
// try to put the device into non-default state, for example,
// this operation below will set the transform
vi.validate(gc);
Graphics2D vig = (Graphics2D) vi.getGraphics();
vig.rotate(30.0f, vi.getWidth() / 2, vi.getHeight() / 2);
vig.drawImage(output, 0, 0, vi.getWidth(), vi.getHeight(), null);
Insets in = frame.getInsets();
frame.getGraphics().drawImage(output, in.left, in.top, null);
if (cnt == 90 && robot != null) {
robot.waitForIdle();
// area where we blitted to should be either white or green
Point p = frame.getLocationOnScreen();
p.translate(in.left + 10, in.top + 10);
BufferedImage bi = robot.createScreenCapture(new Rectangle(p.x, p.y, IMAGE_W / 2, IMAGE_H / 2));
int[] accepted1 = { Color.white.getRGB(), Color.green.getRGB() };
checkBI(bi, accepted1);
// the are where we didn't render should stay white
p = frame.getLocationOnScreen();
p.translate(in.left, in.top + IMAGE_H + 5);
bi = robot.createScreenCapture(new Rectangle(p.x, p.y, frame.getWidth() - in.left - in.right, frame.getHeight() - in.top - in.bottom - 5 - IMAGE_H));
int[] accepted2 = { Color.white.getRGB() };
checkBI(bi, accepted2);
}
Thread.yield();
}
frame.dispose();
System.out.println("Test Passed");
}
use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class TSFrame method createGui.
public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
Frame frame;
done = false;
if (useNonOpaque) {
if (useSwing) {
frame = new NonOpaqueJFrame();
// frame = new NonOpaqueJAppletFrame(gc);
} else {
frame = new NonOpaqueFrame();
}
animateComponent(frame);
} else if (useSwing) {
frame = new JFrame("Swing Frame");
JComponent p = new JButton("Swing!");
p.setPreferredSize(new Dimension(200, 100));
frame.add("North", p);
p = new MyJPanel();
animateComponent(p);
frame.add("Center", p);
} else {
frame = new Frame("AWT Frame") {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
}
};
frame.setLayout(new BorderLayout());
Canvas c = new MyCanvas();
frame.add("North", c);
animateComponent(c);
c = new MyCanvas();
frame.add("Center", c);
animateComponent(c);
c = new MyCanvas();
frame.add("South", c);
animateComponent(c);
}
final Frame finalFrame = frame;
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.setPreferredSize(new Dimension(800, 600));
if (useShape) {
frame.setUndecorated(true);
}
frame.setLocation(450, 10);
frame.pack();
GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
if (useShape) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
System.out.println("applying PERPIXEL_TRANSPARENT");
frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
frame.setTitle("PERPIXEL_TRANSPARENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
}
}
if (useTransl) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
System.out.println("applying TRANSLUCENT");
frame.setOpacity(factor);
frame.setTitle("TRANSLUCENT");
} else {
System.out.println("Passed: TRANSLUCENT unsupported");
}
}
if (useNonOpaque) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
System.out.println("applying PERPIXEL_TRANSLUCENT");
frame.setBackground(new Color(0, 0, 0, 0));
frame.setTitle("PERPIXEL_TRANSLUCENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
}
}
frame.setVisible(true);
return frame;
}
use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class DragInterceptorFrame method initGUI.
private void initGUI(Point location) {
this.setLocation(location);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
DragInterceptorFrame.this.dispose();
}
});
setSize(200, 200);
this.setVisible(true);
}
use of java.awt.event.WindowEvent in project zookeeper by apache.
the class ZooInspector method main.
/**
* @param args
* - not used. The value of these parameters will have no effect
* on the application
*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame frame = new JFrame("ZooInspector");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
iconResource = new IconResource();
final ZooInspectorPanel zooInspectorPanel = new ZooInspectorPanel(new ZooInspectorManagerImpl(), iconResource);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
super.windowClosed(e);
zooInspectorPanel.disconnect(true);
}
});
frame.setContentPane(zooInspectorPanel);
frame.setSize(1024, 768);
frame.setVisible(true);
} catch (Exception e) {
LoggerFactory.getLogger().error("Error occurred loading ZooInspector", e);
JOptionPane.showMessageDialog(null, "ZooInspector failed to start: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
Aggregations