Guest User

Untitled

a guest
Jan 6th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package Polowienie;
  2.  
  3. import java.awt.*;
  4. import java.awt.image.BufferedImage;
  5. import java.io.File;
  6. import java.io.IOException;
  7.  
  8. import javax.imageio.ImageIO;
  9. import javax.swing.JPanel;
  10.  
  11. public class ObrazPanel extends JPanel {
  12.  
  13. /**
  14. *
  15. */
  16. private static final long serialVersionUID = 1L;
  17. private BufferedImage image;
  18.  
  19. public ObrazPanel() {
  20. super();
  21.  
  22. File imageFile = new File("G:\\wykres.jpg");
  23. try {
  24. image = ImageIO.read(imageFile);
  25. } catch (IOException e) {
  26. System.err.println("Blad odczytu obrazka");
  27. e.printStackTrace();
  28. }
  29.  
  30. Dimension dimension = new Dimension(image.getWidth(), image.getHeight());
  31. setPreferredSize(dimension);
  32. }
  33.  
  34. @Override
  35. public void paintComponent(Graphics g) {
  36. Graphics2D g2d = (Graphics2D) g;
  37. g2d.drawImage(image, 0, 0, this);
  38. }
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. package Polowienie;
  47.  
  48. import javax.swing.JFrame;
  49. import javax.swing.JPanel;
  50.  
  51. public class ObrazFrame extends JFrame {
  52.  
  53. public ObrazFrame() {
  54. super("Program obrazkowy");
  55.  
  56. JPanel obrazPanel = new ObrazPanel();
  57. add(obrazPanel);
  58.  
  59. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  60. pack();
  61. setVisible(true);
  62. }
  63. }
  64.  
  65.  
  66.  
  67.  
  68. package Polowienie;
  69.  
  70. import java.awt.EventQueue;
  71.  
  72. public class Test {
  73. public static void main(String[] args) {
  74. EventQueue.invokeLater(new Runnable() {
  75. @Override
  76. public void run() {
  77. new ObrazFrame();
  78. }
  79. });
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment