SO I have this program that is kind of like paint, it lets you draw shapes and lines, but my assignment is to add a menu bar with a sub menu Fil开发者_开发问答e-> About, when Click on the about section. It should pull up a panel or a frame or a something that has a image which I have already made.
However it's not working and I have never actually dealt with images before. All I have is from a Google search and that failed. I know the method is being called from the delightful system.out.println, and a box opens up but there is no picture!~ any help would be very nice.if (e.getActionCommand().equals("About"))
{
System.out.println("stfu");
JFrame about = new JFrame("About");
about.setSize(300, 300);
BufferedImage img = null;
try{
img = ImageIO.read(new File("C:/Users/TehRobot/Desktop/Logo.png"));
}catch (IOException e1)
{
}
You'll want to ...
- Read in the Image with ImageIO.read(...)
- Put your Image into an ImageIcon via the ImageIcon constructor
- Put the ImageIcon into a JLabel via JLabel's
setIcon(...)
method. - And display that JLabel in a dialog such as a JOptionPane (super easy to do) or a modal JDialog (a little more complicated, but not much).
In all this should just take a few lines of code, that's all.
精彩评论