public class Main{
public static void main(String []args){
JLabel c=new JLabel();
c.setIcon(new ImageIcon("picture.png"));
JFrame frame = new JFrame();
frame.setBackground(Color.WHITE);
frame.setUndecorated(true);
frame.getContentPane().add(c);
frame.pack();
BufferedImage bi = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = bi.createGraphics();
c.print(graphics);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
graphics.dispose();
frame.dispose();
}
}
こんにちは、みんな!フレームなしで画面に画像を印刷しようとしています。このコードは、画像を画面に出力する必要があると思います。2 秒待ってから廃棄してください。私は何を間違っていますか?
ところで、エラーはまったく発生しません。プログラムは2秒間生き続けてから終了します。