Guest User

Untitled

a guest
Oct 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  2. InputStream input = classLoader.getResourceAsStream("/resources/image.jpg");
  3. Image logo = ImageIO.read(input);
  4.  
  5. Exception in thread "main" java.lang.IllegalArgumentException: input == null!
  6. at javax.imageio.ImageIO.read(Unknown Source)
  7. at Test.main(Test.java:17)
  8.  
  9. InputStream input = classLoader.getResourceAsStream("image.jpg");
  10.  
  11. System.out.println("Working dir: " + System.getProperty("user.dir"));
  12.  
  13. File imageFile = new File(source);
  14. System.out.println("Canonical path of target image: " + imageFile.getCanonicalPath());
  15. if (!imageFile.exists()) {
  16. System.out.println("file " + imageFile + " does not exist");
  17. }
  18. image = ImageIO.read(imageFile);
  19.  
  20. class Surface extends JPanel {
  21.  
  22. private BufferedImage slate;
  23. private BufferedImage java;
  24. private BufferedImage pane;
  25. private TexturePaint slatetp;
  26. private TexturePaint javatp;
  27. private TexturePaint panetp;
  28.  
  29. public Surface() {
  30.  
  31. loadImages();
  32. }
  33.  
  34. private void loadImages() {
  35.  
  36. try {
  37.  
  38. slate = ImageIO.read(new File("images\slate.png"));
  39. java = ImageIO.read(new File("images\java.png"));
  40. pane = ImageIO.read(new File("images\pane.png"));
  41.  
  42. } catch (IOException ex) {
  43.  
  44. Logger.`enter code here`getLogger(Surface.class.getName()).log(
  45. Level.SEVERE, null, ex);
  46. }
  47. }
  48.  
  49. private void doDrawing(Graphics g) {
  50.  
  51. Graphics2D g2d = (Graphics2D) g.create();
  52.  
  53. slatetp = new TexturePaint(slate, new Rectangle(0, 0, 90, 60));
  54. javatp = new TexturePaint(java, new Rectangle(0, 0, 90, 60));
  55. panetp = new TexturePaint(pane, new Rectangle(0, 0, 90, 60));
  56.  
  57. g2d.setPaint(slatetp);
  58. g2d.fillRect(10, 15, 90, 60);
  59.  
  60. g2d.setPaint(javatp);
  61. g2d.fillRect(130, 15, 90, 60);
  62.  
  63. g2d.setPaint(panetp);
  64. g2d.fillRect(250, 15, 90, 60);
  65.  
  66. g2d.dispose();
  67. }
  68.  
  69. @Override
  70. public void paintComponent(Graphics g) {
  71.  
  72. super.paintComponent(g);
  73. doDrawing(g);
  74. }
  75. }
  76.  
  77. public class TexturesEx extends JFrame {
  78.  
  79. public TexturesEx() {
  80.  
  81. initUI();
  82. }
  83.  
  84. private void initUI() {
  85.  
  86. add(new Surface());
  87.  
  88. setTitle("Textures");
  89. setSize(360, 120);
  90. setLocationRelativeTo(null);
  91. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  92. }
  93.  
  94. public static void main(String[] args) {
  95.  
  96. EventQueue.invokeLater(new Runnable() {
  97.  
  98. @Override
  99. public void run() {
  100. TexturesEx ex = new TexturesEx();
  101. ex.setVisible(true);
  102. }
  103. });
  104. }
  105. }
  106.  
  107. ImageIcon thisImage = new ImageIcon("images/youpic.png");
Add Comment
Please, Sign In to add comment