5 Replies - 255 Views - Last Post: 30 November 2017 - 03:01 PM Rate Topic: -----

#1 jackcwebb   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 17

ImageIo.read not found

Posted 30 November 2017 - 02:40 PM

[
import java.awt.BasicStroke;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;

import java.io.*;
import javax.imageio.*;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class Program7 {
	public static void main(String[] args) {
		
		JFrame frame = new JFrame("Drawing Area with Buttons");
		JMenuBar m = new JMenuBar();
		JMenu menu = new JMenu("Menu Bar");
		DrawPane drwPane = new DrawPane();
		
		m.add(menu);
		
		JButton b1 = new JButton("Oval");
		JButton b2 = new JButton("Image");
		JButton b3 = new JButton("Center");
		JButton b4 = new JButton("Special");
		
		b1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
			frame.getContentPane().add(new DrawPane());
		}});

		b2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
			frame.getContentPane().add(new ImagePane());
		}});

		b3.addActionListener(new ActionListener() {
		@Override
			public void actionPerformed(ActionEvent arg0) {
		}});

		b4.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
			frame.getContentPane().add(new TextPane());
		}});
		
		b1.setBounds(10, 10, 90, 30);
		b2.setBounds(110, 10, 90, 30);
		b3.setBounds(210, 10, 90, 30);
		b4.setBounds(310, 10, 90, 30);
		
		frame.setSize(800, 600);
		frame.setContentPane(drwPane);
		frame.add(b1);
		frame.add(b2);
		frame.add(b3);
		frame.add(b4);
		frame.setJMenuBar(m);
		frame.setLayout(null);
		frame.setVisible(true);
		
	}
}

 class DrawPane extends JPanel{
	@Override
	protected void paintComponent(Graphics arg0) {
		arg0.fillOval(35, 75, 700, 400);
	}
}

 class ImagePane extends JPanel{
	@Override
	protected void paintComponent(Graphics arg0) {
		BufferedImage img = null;
		try{
			  img = ImageIo.read(File("Picture.jpg"));
		}catch(Exception e) {
			e.printStackTrace();
		}
		arg0.drawImage(img, 50, 50, this);
	}
}

 class TextPane extends JPanel{
	@Override
	protected void paintComponent(Graphics arg0) {
		arg0.drawChars(new String("Creativity is hard.").toCharArray(), 10, 10, 200, 100);
	}
}


]
:code:

This post has been edited by modi123_1: 30 November 2017 - 02:41 PM
Reason for edit:: In the future, please use the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: ImageIo.read not found

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14168
  • View blog
  • Posts: 56,760
  • Joined: 12-June 08

Re: ImageIo.read not found

Posted 30 November 2017 - 02:41 PM

Come on Jacky.. ask a question please.
Was This Post Helpful? 0
  • +
  • -

#3 jackcwebb   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 17

Re: ImageIo.read not found

Posted 30 November 2017 - 02:43 PM

There is an error with the line

[img = ImageIo.read(File("Picture.jpg));]

but I cannot figure out what it is. I have already tried adding "new" before File but I am not sure why ImageIo cannot be found

View Postmodi123_1, on 30 November 2017 - 02:41 PM, said:

Come on Jacky.. ask a question please.


Sorry, first time posting and I guess I didn't ask the question in the initial post.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14168
  • View blog
  • Posts: 56,760
  • Joined: 12-June 08

Re: ImageIo.read not found

Posted 30 November 2017 - 02:43 PM

By chance do you remember if Java is case sensitive or not? ;)

https://docs.oracle....io/ImageIO.html
Was This Post Helpful? 0
  • +
  • -

#5 jackcwebb   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 17

Re: ImageIo.read not found

Posted 30 November 2017 - 02:46 PM

View Postmodi123_1, on 30 November 2017 - 02:43 PM, said:

By chance do you remember if Java is case sensitive or not? ;)/>

https://docs.oracle....io/ImageIO.html



Yep..... that would do it. Haha, thank you.
Was This Post Helpful? 0
  • +
  • -

#6 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3562
  • View blog
  • Posts: 16,234
  • Joined: 20-September 08

Re: ImageIo.read not found

Posted 30 November 2017 - 03:01 PM

Quote

img = ImageIo.read(File("Picture.jpg"));

should be
img = ImageIo.read(new File("Picture.jpg"));

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1