Computer Science Canada

including pictures

Author:  underdog [ Thu Jan 19, 2006 10:58 am ]
Post subject:  including pictures

is there a short code to include pictures in your program?

if not, could sum1 send me a method to do it anyway?

thx

Author:  turboliux [ Thu Jan 19, 2006 12:16 pm ]
Post subject: 

code:
import java.awt.*;
import javax.swing.*;

class image {
       
        public static void main (String args[]) {
                JFrame myFrame = new JFrame ("Image");
                JPanel myPanel = new JPanel ();
                ImageIcon icon = new ImageIcon("image.jpg");
                JLabel myLabel = new JLabel ("some text", icon, JLabel.RIGHT);
               
                myFrame.setDefaultCloseOperation(myFrame.EXIT_ON_CLOSE );
                myFrame.getContentPane().add(myPanel, BorderLayout.CENTER);
               
                myPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
                myPanel.add(myLabel);
               
                myFrame.pack();
                myFrame.show();
        }
}

Author:  turboliux [ Thu Jan 19, 2006 12:22 pm ]
Post subject: 

if you have already your own program, then include this into your constructor, or main method:
code:
ImageIcon icon = new ImageIcon("image.jpg");
JLabel myLabel = new JLabel ("some text", icon, JLabel.RIGHT);
myPanel.add(myLabel);


: