Putting Images In GUI / Images In Source File Don't Seem To Be Recognized

Jun 7, 2014

This is my class with the GUI:

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

[code]....

Eclipse error message:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at GUI.<init>(GUI.java:26)
at Apples.main(Apples.java:7)

i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference.

View Replies


ADVERTISEMENT

How To Add Images To Program

Dec 14, 2014

I just finished a tutorial on youtube that covers the basic java, and now i want to try and make a game / program thing, only problem is that i have never worked with graphics before (i have tried to make ovals, rectangles, and other things with the paint method tho )

I know how to make a jframe and a jpanel, and i feel like i can make a simple "game" (not a complicated one, just a simple one with a guy walking around on the screen) in fact i have already make a such game, where you are a oval walking around on the screen, so thats not really my problem.

My problem is that i want to draw an image on the screen that can walk around instead of the oval, but how to do that. I have made a new project and set up the jframe and jpanel, and my code looks like this:

(main)

import javax.swing.JFrame;
 public class main_class {
public static void main(String[] args){
 JFrame f = new JFrame();
f.setTitle("title");
f.setVisible(true);
f.setSize(800,600);

[code]...

but once again, i get a blank jframe with no image and no "test" string . How i can display images on the screen?

View Replies View Related

Scaling Images Using JAI

Sep 25, 2014

I have code to convert tiff image to PNG image.I want to scale my PNG image to 800X800 without losing quality.I use the below code but seems doesn't work.Its not resizing the image to specific height and width.

Java Code:

SeekableStream seekableStream = new FileSeekableStream(file);
ImageDecoder imageDecoder = ImageCodec.createImageDecoder(
Constants.TIFF, seekableStream, null);
RenderedImage renderedImage[] = new RenderedImage[imageDecoder
.getNumPages()];
for (int i = 0; i < imageDecoder.getNumPages(); i++) {

[code]...

View Replies View Related

Images Not Loading

Nov 15, 2011

I usually code in PHP, C++ and ActionScript.I'm trying to follow an example of how to add images to a full screen application. What he does is that he adds a JPG background image, and then 4 PNG images. I tried to do it like I always do, by writing the code by myself looking at the book. It didn't work. I searched for errors in the code, changed some things, tried different things, but it didn't work. Then I tried to use his own code, that I downloaded from his website. That didn't work either.. I tried to find another way to add an image, and I can't seem to figure out a way to implement images in any other way into this class that's written in this book.. My Java programming level isn't just high enough.

Here's the code for the file where the images load, downloaded from the authors website (I've modified the brackets and some spaces so that it becomes easier to read):

Java Code:

import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class ImageTest extends JFrame {
public static void main(String[] args) {
DisplayMode displayMode;

[code]....

View Replies View Related

How To Get Images From Jsoup

May 12, 2014

I know how to get the link for the GIF but how do I get the image and use it in java?

View Replies View Related

Changing JPG DPI Value For Some Images

Sep 25, 2014

I am currently working on Java software which resize jpeg images and change DPI also. For JPEG images having app0JFIF node it works fine and the images new DPI is reflected in Photoshop. But if app0JFIF node not exist, I am trying to create a new one and set the DPI value there. Everything is going proper but if I open these images in photoshop it does not reflect new DPI but the size changes.

Java Code:

double dpi_in_inch = 0.393701 * newres;
File file1 = new File(imgName);
image = ImageIO.read(file1);
int wd, hi;
wd = (int) (newsize * dpi_in_inch);

[Code] ...

View Replies View Related

Using Images As Buttons In Processing

May 5, 2015

I'm just wondering whether it is possible to use images as a button in Java. I have two images that I want to use to create a rollover effect, is this possible? And then I would like to reset my java program when the button is clicked, is this also possible?

View Replies View Related

Error When Adding Images?

Jan 16, 2014

I have been trying my hand at making 2d top down view games and have found myself repeatedly using the same code so i created a file with all the functions so when it is down i just import the jar and dont have to keep rewriting functions. I have trouble because the background is loaded on the screen and i dont know why as i didn't tell it to load. In fact I set the panels visiblity to false. Both of my classes are in the same package. Why I still get the Image.

Walking Turtle
Java Code: import javax.swing.*;
import java.awt.event.*;
public class turtleWalker extends JFrame{
public static void main(String[] args){
JFrame frame = new JFrame("Walking Turtle");

[code]....

View Replies View Related

How To Import Many Images Into Array

Feb 24, 2015

I am still playing around with decks of cards, and am now trying to implement some visualizations using Applets.

Here is how I enter my deck of cards into an array list: this works just fine:
 
String[] Suits = new String[]{"S","H","D","C"};
String[] Values = new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
ArrayList<String> deck = new ArrayList<String>();
for(String suit : Suits) {
for(String value : Values) {
deck.add(suit+"_"+value);
}
}

The end result of this is an array 'deck' which contains a string representing each of the 52 playing cards. Great.

Now I would also like to use some pictures for future implementations I am working on. I have 52 images (.png, though I doubt it matters) stored in the right place. They are named as "H_5.png", and "S_A.png", for example, just as I named the cards in the previous array. I would like to do something as follows

ArrayList<Image> deckpic = new ArrayList<Image>();
for(String suit : Suits) {
for(String value : Values) {
deckpic.add(getImage(suit+"_"+value+".png"));
}
}

Now of course this doesn't work. The line

suit+"_"+value+".png"

is a string, not the name of a file. How I have previously loaded images is to use something like this:

the_pic = getImage("picture_of_pony.jpg");

but of course I can't use the quotations in my card loop, since I want "suit" and "value" to range and not just be the strings suit and value.

View Replies View Related

Images Not Displaying Properly

Nov 16, 2014

My code:

import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.lang.*;
import java.awt.image.*;
import java.net.URLDecoder;

[Code] .....

I my images (including the one I created) are all 32x32. I'm trying to get a player Icon and have them be on a field of grass. Currently, I just get:

(see Attached)

I don't know where my Images are rendering.

B = blank
. = grass
p = player

.
.
.
.
. p
.
.
b

View Replies View Related

How To Use Images As Backgrounds For JPanel

May 20, 2014

I am trying to use images as my backgrounds for my JPanel.the problem is when I run the program the images don't show at first.T hey start to show after I have switched to another panel and then switch back. Here are my codes

//for loading image
static public Image LoadIcon(String file) {
URL icoURL = windows.class.getResource(file);
Image img = Toolkit.getDefaultToolkit().createImage(icoURL);
return img;

[Code] ......

View Replies View Related

Using Images In JLabel And JPanel

Sep 26, 2014

I read many posts online and watched tutorials on YouTube. I can't seem to get this work. Notice I am not using any drawing/graphics capabilities - I'd like to keep it this way as we have not gotten that far yet in my studies.The image is in a source folder titled Images under/in my project.

Java Code:

private JPanel jpImage = new JPanel();
private JLabel lblImage;
private ImageIcon image;
private Image img;
// All those above defined prior to method
// Within method (relevant to code above) ...

[code]....

View Replies View Related

Why Images In Applet Not Showing

Aug 30, 2014

So I am trying to make this java applet that will display a random image of three that is a sub folder of my src folder within my project.

When you run the project currently all you get is a white applet. Here is the code:

import java.applet.Applet;
import java. awt.*;
 public class myPictures extends Applet {
Image action;
public void paint(Graphics g){
int rint = (int)(Math.random() * 3);
if(rint == 0){
action = getImage(getDocumentBase(), "../../images/bee3.jpg");
} else if(rint == 1){
action = getImage(getDocumentBase(), "../../images/bee1.jpg");
} else {
action = getImage(getDocumentBase(), "../../images/bee2.jpg");
} } }

View Replies View Related

Background Overlapping Images

Jan 7, 2014

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class sample{
public static void main(String args[]){
JFrame frame = new JFrame();
frame.setSize(300,300);

[code]....

To limit the amount of drawing done i want unmoving objects to be painted once. So i set a boolean. When it first load the boolean is false so it draws then after first draw i never want it to draw the objects agian but leave them on the screen. Now in this if you run it you get a black screen.

If you didnt have the "getContentPane().setBackground(Color.black)" it would work fine and show a blue brick. Is there something I don't understand about the setBackgound Function that makes it automatically redone even when not called? and if so how do i overwrite this?

View Replies View Related

Application For Images Duel

May 20, 2014

I need to make android app for image comparison. It has to show two images and user will choose which image he prefer by using radio button . After clicking one radio button app should save the result of a duel and show another pair of images.

If there is N images it will be ((n*n)-n)/2 duels. I think of something like this - [URL] .... but instead of 2 radio buttons it will be 9 - 4 for each image (depending on preference) and 1 neutral button(no preference).

How to achieve that. I started using java and eclipse recently only so it is all new to me. I made an activity in xml so far and I tried to make class for changing imageview 1 and 2 assuming that all images will be named a1,a2,a3 .

package com.example.ahp;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Develop Carousel For Images

Nov 6, 2014

how to develop carousel for images using java swing

View Replies View Related

Best Way To Deploy App With HTML And Images Files?

Feb 3, 2015

You basically paste a url Into a textarea and choose an Image for the link.The Image link Is then appended to a html file.

I'd like to put everything In a single jar file but I'm not sure what to do so the user can access the html file.

The only two options I can think of are:

a) create the html document on the fly when the jar runs.

b) Is to run a bat command when the jar Is executed that will extract the jar files.

The user can either choose from a number of Images In the logos folder for common websites or add new Images. Since the folder isn't empty , It seems like extracting the jar files Is necessary.

View Replies View Related

Swing/AWT/SWT :: Why Delays In Drawing Images

Jun 17, 2014

I have a question about the execution of code to draw images relative to code that comes after that. I don't normally do this sort of thinghere's the problematic code:

int stn = 0;
while (stn < 10)
{
glb1.xOfText += 20;
glb1.yOfText += 20;
gc1.drawImage(glb1.img1 , glb1.xOfText , glb1.yOfText);
TimeKeeper.pause(500);
stn++;
}

Where glb1 is a final reference to an object that holds common data for the game.while its x and y values say they are for text, they are also used for image placement (at least during this testing phase.)

gc1 is the "graphics context" of the canvas that the images are being drawn on.

The person who wrote this said, "When the attached code is run, the calls to TimeKeeper.pause(500), which in turn call Thread.sleep(500), are all executed in row, and then the results of drawing the image 10 times is displayed. (I know because some of the previous image pastes left some visual data behind.)"

I recall from reading about drawing graphics (a long time ago) that drawImage() could take time, but I don't know why the thread does not indeed sleep between calls to drawImage().

View Replies View Related

Swing/AWT/SWT :: Adding Images To JLIST

Apr 14, 2015

I am currently creating a Twitter Application within Java Swing using JSON. I have the JList populating with Home feeds but i also want to get Images displaying next to the Text ...

currently all i am getting is [URL] ....

So a am able to get the URL Link but getting that to a Image seems to be the problem

/ArrayLists
final ArrayList<String> TweetArray = new ArrayList<String>(); //Array List for Users Tweets..
final static ArrayList<String> incomingTweets = new ArrayList<String>(); //ArrayList for Incoming Tweets.
ArrayList<String> arrayImages = new ArrayList<String>();//ArrayList for incoming Tweet Profile Images
private Map<String, ImageIcon> imageMap;

[Code] ....

View Replies View Related

JSF :: How To Handle Images For ECommerce Site

Feb 25, 2015

I have an ecommerce site that has about 100000 SKUs. What is the best practice for handling all the product images as far as where to store them and how to display them on the pages? Should I have a separate HTTP server to serve the images?

View Replies View Related

Swing/AWT/SWT :: Display Images According To Number?

Mar 27, 2014

The code below is just the GUI for a slot machine. Currently when play is clicked it displays the random number, I'm trying to make it so each random number displays an image in the GUI instead. For example if the random numbers were 2,2,3 it would display Cherry, Cherry, Bells. I started changing field1 to the image but realised I was on the wrong track as it would just display the same image not one allocated to a number. I've left in what I started doing.

how to do it?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SlotMachineGUI {
JPanel mainPanel;
SlotMachine slotEngine;

[code]....

View Replies View Related

Swing/AWT/SWT :: Drawing Images That Are GIFs

Dec 20, 2014

how to phrase the question. I created a small applet in java.. it allows me to move a toon around a blank applet window. I am using four gif files that have a walking animation in them. The issue i am having is after moving around the gif just flashes in and out really quickly.. when i start the program, moving up and down seems to be working perfectly fine, but the moment i move left or right it starts messing up for all directions. here is my code.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CharactorMove extends JApplet implements KeyListener

[code]....

View Replies View Related

Insert Smiley Images In JTextArea?

Feb 23, 2015

making an app in java.i m making app that should insert smilyes in textarea while sending a message.

View Replies View Related

Memory Game GUI Images Not Displaying

Nov 14, 2014

package memorygame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Random;
import java.awt.*;
public class MemoryGame extends JFrame{

[Code]...

View Replies View Related

JSF :: Load Images From CSS On Composite Component?

May 9, 2014

I have an issue about loading images from css using a composite component. The folder structure is:

resources
resources -> css -> componentname
resources -> images - > componentname
resources -> WEB-INF

If i write in the css something like

border-image: url(resources/images/componentname/image.png) !important;
or
border-image: url(images/componentname/image.png) !important;

i have a 404 error and i can't see the image.

I able to load the image only if i write path with context-root:

border-image: url(/<CONTEXTROOT>/resources/images/componentname/image.png) !important;

but i can't write explicit context root in css files!!

So, i tried to use resource EL variable:

border-image: url(#{resource[image/componentname/image.png]}) !important;

but this last way render

border-image: url("/<CONTEXTROOT>/javax.faces.resource/images/componentname/image.png.faces.faces") !important;

and i not able to replicate the right way written above.

The project is developed with RSA9 and WebSphere Portal 8, but if i try to execute it in NetBeans (no portal) it run correctly!

View Replies View Related

Easy Way To Load Images Using For Loop?

Apr 17, 2015

I am looking for a way to tidy up my setup at the beginning of my java project.

piece[0].picture = loadImage("Piece1.png");
piece[1].picture = loadImage("Piece2.png");
piece[2].picture = loadImage("Piece3.png");
piece[3].picture = loadImage("Piece4.png");
piece[4].picture = loadImage("Piece5.png");
piece[5].picture = loadImage("Piece6.png");

[code]...

I though a for loop might work but im not sure how id get it to use the file names above

for(int l=0; l<=76; l++){
piece[l].picture = loadImage("part unsure about")
}

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved