Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- InputStream input = classLoader.getResourceAsStream("/resources/image.jpg");
- Image logo = ImageIO.read(input);
- Exception in thread "main" java.lang.IllegalArgumentException: input == null!
- at javax.imageio.ImageIO.read(Unknown Source)
- at Test.main(Test.java:17)
- InputStream input = classLoader.getResourceAsStream("image.jpg");
- System.out.println("Working dir: " + System.getProperty("user.dir"));
- File imageFile = new File(source);
- System.out.println("Canonical path of target image: " + imageFile.getCanonicalPath());
- if (!imageFile.exists()) {
- System.out.println("file " + imageFile + " does not exist");
- }
- image = ImageIO.read(imageFile);
- class Surface extends JPanel {
- private BufferedImage slate;
- private BufferedImage java;
- private BufferedImage pane;
- private TexturePaint slatetp;
- private TexturePaint javatp;
- private TexturePaint panetp;
- public Surface() {
- loadImages();
- }
- private void loadImages() {
- try {
- slate = ImageIO.read(new File("images\slate.png"));
- java = ImageIO.read(new File("images\java.png"));
- pane = ImageIO.read(new File("images\pane.png"));
- } catch (IOException ex) {
- Logger.`enter code here`getLogger(Surface.class.getName()).log(
- Level.SEVERE, null, ex);
- }
- }
- private void doDrawing(Graphics g) {
- Graphics2D g2d = (Graphics2D) g.create();
- slatetp = new TexturePaint(slate, new Rectangle(0, 0, 90, 60));
- javatp = new TexturePaint(java, new Rectangle(0, 0, 90, 60));
- panetp = new TexturePaint(pane, new Rectangle(0, 0, 90, 60));
- g2d.setPaint(slatetp);
- g2d.fillRect(10, 15, 90, 60);
- g2d.setPaint(javatp);
- g2d.fillRect(130, 15, 90, 60);
- g2d.setPaint(panetp);
- g2d.fillRect(250, 15, 90, 60);
- g2d.dispose();
- }
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- doDrawing(g);
- }
- }
- public class TexturesEx extends JFrame {
- public TexturesEx() {
- initUI();
- }
- private void initUI() {
- add(new Surface());
- setTitle("Textures");
- setSize(360, 120);
- setLocationRelativeTo(null);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- TexturesEx ex = new TexturesEx();
- ex.setVisible(true);
- }
- });
- }
- }
- ImageIcon thisImage = new ImageIcon("images/youpic.png");
Add Comment
Please, Sign In to add comment