フレームに怖いイメージがポップアップされるようにしようとしています。私はJOptionPaneを使って質問しています。もし彼らが簡単に怖がっていると言ったら、それは、ピエロなどのイメージをポップアップさせます。 問題は、JFrameを作成するメソッドを作成しようとすると動作しないことです。メソッドを呼び出そうとすると機能しません。 は、ここでの問題は、あなたが方法でのJFrameを作成することで、コードフレーム作成メソッド
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Boo {
public static void main(String[] args) throws IOException {
int x = JOptionPane.showConfirmDialog(null,"Do you consider yourself
easily scared?",null,JOptionPane.YES_NO_OPTION);
if(x == JOptionPane.YES_OPTION){
String fileString =
"C:\\Users\\20jdominiecki\\Downloads\\68b8a6e159169897cc01d8d34d184962.jpg";
frameCreator();
}
int y = JOptionPane.showConfirmDialog(null,"Like what you
see?",null,JOptionPane.YES_NO_OPTION);
if (y == JOptionPane.NO_OPTION)
{
String fileString = "C:\\Users\\20jdominiecki\\Downloads\\doggo.jpg";
frameCreator();
}
}
public void frameCreator(String fileString) throws IOException{
File file = new File(fileString);
BufferedImage image = ImageIO.read(file);
JLabel label = new JLabel(new ImageIcon(image));
JFrame f = new JFrame();
f.getContentPane().add(label);
f.pack();
f.setLocation(0,0);
f.setVisible(true);
}
}
正確に何をしたいですか?問題は何ですか?私のシステムで引数が渡された後、正しく動作しています – Balasubramanian