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
ADVERTISEMENT
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
Jan 18, 2014
I want to be able to get an image online and display on my JPanel but for some reason my image wont load and just shows a blank square, but when I try to load an image from my hard drive it works just fine.
Here is what I was trying to do:
Java Code:
BufferedImage image;
try
{
image = ImageIO.read(SiteMainMenu.class.getResource("insert link here"));
}
catch(Exception e)
{
} mh_sh_highlight_all('java');
View Replies
View Related
Mar 27, 2014
I'm working on loading SVG images on Jpanel using "Apache(tm) Batik SVG Toolkit" , but after the image get loaded it has "white background" and "not transparent" one like PNG images.
I checked "fill" of rect attribute on the xml file of the svg image and it was correctly set to none, I also Tested the image on html document and it was trasparent, but in my java app it has white background.
The Question is there any way to load SVG images with transparent background on Jpanel ?
View Replies
View Related
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
View Related
Jun 9, 2014
I am making a game in java and i want to make a title screen. What I am trying to do is make a jpanel and load another jpanel when a button is pressed in one of the japenls. Here is the code for the runner
import java.awt.BorderLayout;
import javax.swing.JFrame;
public class Runner extends JFrame {
// Have these set up so they can be seen everywhere
public static final int GAMEWIDTH = 540;
public static final int GAMEHEIGHT = 710;
static boolean loading = false;
[Code] ....
here is the code for the jpanel that loads the other jpanel
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
[Code] ...
How do load a jpanel when a button is pressed in another jpanel
View Replies
View Related
Jun 17, 2014
I have a Main() class that extends JPanel and I'm trying to add Card() that also extends JPanel.When I add a Card() or Main() object to the JFrame directly, it works fine. The problem arises when I try to add a Card() object to the Main() object.
I edited the code a little bit to make it easier to read so hopefully it's fine.
Main() code:
public class Main extends JPanel implements Runnable {
// HARDCODED OPTIONS
public static final int WIN_WIDTH = 1200;
public static final int WIN_HEIGHT = 800;
public static final int GRID_X = 9;
public static final int GRID_Y = 5;
[Code] ...
View Replies
View Related
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
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
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
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
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
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
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
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
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
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
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
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
Nov 6, 2014
how to develop carousel for images using java swing
View Replies
View Related
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
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
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
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
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
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