Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class JavaApplication30 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- JFrame f = new JFrame();
- //f.setSize(800,600);
- String imagePath = "http://duke.kenai.com/misc/Bullfight.jpg";
- Image image = null;
- try
- {
- URL url = new URL(imagePath);
- image = ImageIO.read(url);
- }
- catch (IOException e)
- {
- System.out.println(e);
- }
- JPanel backgroundPanel=new ImagePanel(image);
- backgroundPanel.setLayout(null);
- backgroundPanel.setSize(638, 311);
- JPanel drawingPanel=new DrawingPanel();
- drawingPanel.setSize(638, 311);
- drawingPanel.setOpaque(false); //make it transparent
- backgroundPanel.add(drawingPanel);
- f.add(backgroundPanel);
- f.pack();
- f.setVisible(true);
- }
- static class ImagePanel extends JPanel {
- private Image img;
- public ImagePanel(Image img) {
- this.img = img;
- Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
- setPreferredSize(size);
- setMinimumSize(size);
- setMaximumSize(size);
- setSize(size);
- setLayout(null);
- }
- public void paintComponent(Graphics g) {
- g.drawImage(img, 0, 0, null);
- }
- }
- static class DrawingPanel extends JPanel {
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(Color.GREEN);
- g.fillRect(0, 0 , 100, 100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement