use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class ControlCharacter method createAndShowGUI.
static void createAndShowGUI() {
frame = new Frame();
frame.setSize(300, 300);
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
super.paint(g);
lock.lock();
isPainted.signalAll();
lock.unlock();
}
};
panel.addKeyListener(new KeyListener());
frame.add(panel);
lock.lock();
frame.setVisible(true);
panel.requestFocusInWindow();
try {
isPainted.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
lock.unlock();
}
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class TexturePaintPrintingTest method doPaint.
public void doPaint(Graphics2D g2d) {
BufferedImage patternImage = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
Graphics gImage = patternImage.getGraphics();
gImage.setColor(Color.WHITE);
gImage.drawLine(0, 1, 1, 0);
gImage.setColor(Color.BLACK);
gImage.drawLine(0, 0, 1, 1);
gImage.dispose();
Rectangle2D.Double shape = new Rectangle2D.Double(0, 0, DIM * 6 / 5, DIM * 8 / 5);
g2d.setPaint(new TexturePaint(patternImage, new Rectangle2D.Double(0, 0, DIM * 6 / 50, DIM * 8 / 50)));
g2d.fill(shape);
g2d.setPaint(Color.BLACK);
g2d.draw(shape);
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class GifTransparencyTest method show.
public void show() {
JPanel p = new JPanel(new BorderLayout()) {
public void paintComponent(Graphics g) {
g.setColor(Color.blue);
g.fillRect(0, 0, getWidth(), getHeight());
}
};
p.add(new ImageComponent(src), BorderLayout.WEST);
if (dst != null) {
p.add(new ImageComponent(dst), BorderLayout.EAST);
}
JFrame f = new JFrame("Transparency");
f.add(p);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class HiDPIRobotScreenCaptureTest method main.
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
return;
}
Frame frame = new Frame();
frame.setBounds(40, 30, 400, 300);
frame.setUndecorated(true);
Panel panel = new Panel(new BorderLayout());
Canvas canvas = new Canvas() {
@Override
public void paint(Graphics g) {
super.paint(g);
int w = getWidth();
int h = getHeight();
g.setColor(COLORS[0]);
g.fillRect(0, 0, w / 2, h / 2);
g.setColor(COLORS[1]);
g.fillRect(w / 2, 0, w / 2, h / 2);
g.setColor(COLORS[2]);
g.fillRect(0, h / 2, w / 2, h / 2);
g.setColor(COLORS[3]);
g.fillRect(w / 2, h / 2, w / 2, h / 2);
}
};
panel.add(canvas);
frame.add(panel);
frame.setVisible(true);
Robot robot = new Robot();
robot.waitForIdle();
Thread.sleep(200);
Rectangle rect = canvas.getBounds();
rect.setLocation(canvas.getLocationOnScreen());
BufferedImage image = robot.createScreenCapture(rect);
frame.dispose();
int w = image.getWidth();
int h = image.getHeight();
if (w != frame.getWidth() || h != frame.getHeight()) {
throw new RuntimeException("Wrong image size!");
}
if (image.getRGB(w / 4, h / 4) != COLORS[0].getRGB()) {
throw new RuntimeException("Wrong image color!");
}
if (image.getRGB(3 * w / 4, h / 4) != COLORS[1].getRGB()) {
throw new RuntimeException("Wrong image color!");
}
if (image.getRGB(w / 4, 3 * h / 4) != COLORS[2].getRGB()) {
throw new RuntimeException("Wrong image color!");
}
if (image.getRGB(3 * w / 4, 3 * h / 4) != COLORS[3].getRGB()) {
throw new RuntimeException("Wrong image color!");
}
}
use of java.awt.Graphics in project jdk8u_jdk by JetBrains.
the class MultiResolutionSplashTest method getScaleFactor.
static float getScaleFactor() {
final Dialog dialog = new Dialog((Window) null);
dialog.setSize(100, 100);
dialog.setModal(true);
final float[] scaleFactors = new float[1];
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
float scaleFactor = 1;
if (g instanceof SunGraphics2D) {
scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
}
scaleFactors[0] = scaleFactor;
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
dialog.dispose();
return scaleFactors[0];
}
Aggregations