Swing/AWT/SWT :: Displaying Image Using ImageIcon?

Jul 5, 2014

I'm currently following this Java tutorial:[URL]

I'm at the Image part of this chapter and I wrote/copied these 2 classes:

[URL]

The error:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at image.Board.<init>(Board.java:17)
at image.Image.<init>(Image.java:10)
at image.Image.main(Image.java:20)

I'm fairly certain the problem is the path in this piece of code:

ImageIcon ii = new ImageIcon(this.getClass().getResource("C:GebruikersKristofferworkspaceImagessrcimageNature.jpeg"));

I've done some research and found that I should place the image in the same folder as my .java files, which I did [URL] but the problem still persists.

View Replies


ADVERTISEMENT

JFrame - ImageIcon Not Displaying?

Apr 14, 2014

why my image may not be showing. Note I am using eclipse.

Window.java:

import javax.swing.*;
 public class Window {
private JFrame gameWindow;
 public Window() {
gameWindow = new JFrame("Tamagotchi!");

[code]....

I have used file.exists() and this returns true, and file.length() which returns the correct file size.

System.out.println(backgroundImage) returns "splash.png" so thats ok.

Why then is my image not showing?

View Replies View Related

Swing/AWT/SWT :: Displaying Image On Button Press

Mar 22, 2014

I have been reading some java guides here [URL] .... and was trying to put a bit of what I have learnt into practice but am having some difficulty. Basically, using netbeans IDE I have created a new jFrameform so that I can place swing components in design mode. What I want to create isnt overly complicated but I just cant seem to get it. In design I have simply added a panel and a button. When I press the button I want to display an image I have located at:

/resources/images/numbers/1.png.

This is my code so far (most of it has been automatically generated from me adding things via design mode:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package test;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

[Code] ....

I assume I need something like below somewhere , do i need to create a draw method? if so how do I call it as it is expecting graphics2d as a parameter, what would I pass into it?

BufferedImage img = null;
try {
img = ImageIO.read(new File("/resources/images/numbers/1.png"));
} catch (IOException e) {
}

View Replies View Related

Image Is Not Displaying On JFrame

Jan 16, 2014

I am trying to make a little game that moves a picture of peter griffin around. I wrote the code, but the image is not displaying on my JFrame.

Java Code:

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.KeyEvent;

[code]...

View Replies View Related

Applet Image Not Displaying

May 4, 2014

I want to display a picture but it isn't working:

public class BildApplet extends Applet {
Image car;
public void init() {
this.setBackground(new Color(200, 200, 255));
car = this.getImage(getDocumentBase (), "redcar.gif");

[Code] ....

Why not?

View Replies View Related

Erasing First Buffered Image Before Displaying Second One

Feb 12, 2015

How would I go about erasing the first buffered image before displaying the second one and eventually a third and fourth so that it appears the image is moving across the screen?

myBuffer.drawImage(myArray[0].getImage(), xPos, yPos, null);
myBuffer.drawImage(myArray[0].getImage(), xPos + width, yPos, null);

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class KarelPanel extends JPanel {
private static final int WIDTH = 395, HEIGHT = 391; //constants

[Code] .....

View Replies View Related

Java GUI Displaying Image Icon

Dec 2, 2014

how to display a jpg image on a through a Jlabel. I am sure it is a simple error but I am still new to GUI's. line 31 to 35 you can see the ImageIcon and file wrapped in the JLabel. I verified its in the correct location and file name, but usually fails (i thought) when it is not correct.

Java Code:

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

[code]....

View Replies View Related

Swing/AWT/SWT :: Image Manipulation - Create Application Where Image Is Displayed On One Label

Apr 7, 2014

Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later the user has to retrieve the entire image by viewing a small part of the image. I have already displayed the full image on the Label, now i don't know how to split the image and store it part wise in the database.

View Replies View Related

Displaying GIFs In Swing

Feb 12, 2014

How is it possible to put a gif in swing that automatically changes the frame rate by itself? g.drawImage("file.gif") won't work.

View Replies View Related

Swing/AWT/SWT :: Displaying PNG In A Window

Jan 31, 2014

That's my third day working in Java using Swing and the IntelliJ Idea IDE.I'm trying to do something as simple as displaying a PNG in a window, and I'm doing this:

public class AboutRapide {
public JPanel mainPanel;
private void createUIComponents() {
mainPanel = new ImagePanel();

[cod]....

the problem is that, in the paintComponent method, the Image is never found when I run my app from the IDE, but it is when I run it from Finder in my Mac. Same application. I think it relates to how the application is launched so I guess what's a proper way to refer to a resource file with an image so it can be displayed no matter how the application is launched?Also if I generate a Jar for the application, as the resource gets into the Jar compressed file, it can't also be loaded.

View Replies View Related

Swing/AWT/SWT :: Displaying Results In A Message Box?

May 8, 2014

how to display results in a PLAIN_MESSAGE. My program is converting hex to decimal and displaying the results. Here's the code:

package pkgfinal;
import javax.swing.JOptionPane;
import java.util.Scanner;
public class Final {
public static int Convert(String userInput, int base){
int running_sum = 0;

[code].....

View Replies View Related

Swing/AWT/SWT :: FPS Counter Only Displaying Ideal FPS

Mar 23, 2014

I have an fps counter in my game loop:

public void run()
{
long currentTime,timeDiff;
prevTime = System.nanoTime();
accumulator = 0;
boolean TRUE = true;

[code]...

When I print the fps variable to the terminal window, it show a value of ~59.9998 - very close to the frameRate of 60. That is to be expected, and works well. The problem is that when I deliberately make the game go really slow, by spamming a bunch of enemies, the game looks slow, but the FPS is still apparently ~59.9998. I thought that maybe the paint() method was not calling when it was supposed to, but that might not be the case.

This FPS counter should be working, I can't see where I have gone wrong. Is there a problem with the code, or is there another problem that might cause the screen to be redrawn 10 times a second with an FPS of 60?

View Replies View Related

Swing/AWT/SWT :: Java Browser Not Displaying Google

Jul 28, 2014

my web browser isn't displaying any web page. When I create the method editorPane.setPage(), it takes forever (about 20 seconds) to show nothing. It'll load the web browser after the 20 seconds of waiting. Here is my code:

public class Browser extends JInternalFrame {

/**
*
*/
private static final long serialVersionUID = 4589041456161585394L;
public Browser() {
super("Browser", true, true);
this.setLayout(new BorderLayout());
this.setVisible(true);
this.setSize(Desktop.getSingletonInstance().getWidth(), Desktop.getSingletonInstance().getHeight());

[code]....

View Replies View Related

Swing/AWT/SWT :: Buttons Not Displaying Till Mouseover Them?

Jan 19, 2012

I set out to make a Tic-tac-toe (Cross and Noughts) game to test my learning so far. While things have gone pretty well so far, I am absolutely stumped by my current issue. When I compile and run the code, the Grid of buttons that I generate do not appear. However, if I mouse over the window, they seem to then get refreshed/repainted. I cannot for the life of me figure out why this is happening. From Googling the issue, it seems this is either an issue with the layout manager or related to a thread conflict with the GUI? [URL] ....

I'm listing out the code for the game class and the button class.

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class CrossNoughtsGame {
private JFrame frame;
private JPanel mainPanel;
private ArrayList<CNButton> buttonList = new ArrayList<CNButton>();
private boolean isX = true;

[Code] ....

View Replies View Related

Unable To Compare ImageIcon In A Button Against Another

Dec 6, 2014

I am trying to compare a ImageIcon in a button against another. The method which has the issue is checkMatrixValues() third from the bottom of this post. I did my best to make this post flow as I am looking at the issue, hope it is not confusing.

the view class creates a matrix of Mybuttons and Mybuttons extends JButton. I did this because I need Mybuttons to have fields within each button.

public class View extends Mybuttons{
private static final long serialVersionUID = 1L;
JFrame frame;
JPanel matrixPanel, optionsPanel;
Mybuttons[][] matrixBtn;

[Code]...

MyButtons has a few values and methods in it but here is a peek at the fields. This post is concentrating on ImageIcon greenIcon and ImageIcon redIcon.

public class Mybuttons extends JButton {
private static final long serialVersionUID = 1L;
Boolean barrier,startNode,targetNode,visited;
public ImageIcon greenIcon = new ImageIcon("green.png");
public ImageIcon redIcon = new ImageIcon("red.png");
private ImageIcon yellowIcon = new ImageIcon("yellow.png");
private ImageIcon resetIcon = new ImageIcon("null");
public int counter;

In the controller class one method checks to make sure there is one start and one end point by calling checkMartixValues when the enter button is pressed: (FYI greenIcon is start and redIcon is end)

if(e.getSource()==view.enterBtn){
for(int i=0;i<25;i++){
for(int j=0;j<25;j++){
//Validates matrix to see if there are more then one
//red or green button pressed
checkMartixValues(view.matrixBtn[i][j]);

[Code]...

When I do the following:

if(matrixBtn.getIcon()==view.matrixBtn.redIcon)

It runs but jumps to the else statement. Again it is saying redIcon is not a field yet I am able to access other fields from view.matrixBtn. I even tried:

if(matrixBtn.getIcon()==buttons.redIcon) //compiles but will skip to else statement too 
//remember the above if statement is in the same controller class which declares
public class Controller {
/*The view class holds the GUI and creates a matrix of MyButtons.
*Each of MyButtons will be treated as a node in the Controller Class
*Consider MyButtons as the Model in the MVC design
* */
View view;
Mybuttons buttons;

View Replies View Related

ImageIcon Setter And Getter Methods Not Working

Jan 3, 2015

I have been assigned with a task to have a class which has the methods setImage and getImage. These methods are meant to set the ImageIcon by using the url taken from another class and the getImage method is meant to return the ImageIcon that was set before hand. The problem is that i'm not really familiar with ImageIcon so the code in both my methods is giving out errors and i just can't figure out why. Heres the code in the class that has the setImage and getImage methods:

public class Die implements DieInterface {
private ImageIcon [] image = new ImageIcon[6]; //the number of images that would be stored in this array is 6 (six faces of the dice)
ublic Die()
{
//This puts images into the images array(the different die faces)
image = new ImageIcon[6];

[code]....

And this is where i call the methods (set and get methods) in the other class:

die1.setImage(new ImageIcon(Dice.class.getResource("face1.png")));
die1.getImage();

View Replies View Related

How To Update JLabel Or ImageIcon Anytime On Press A Button

Apr 15, 2014

I am trying to do a program about a contact agenda, now, I have one JPanel that contains three sub panels (GridLayout(1,3)) where I have in the left the picture of the Contact, the middle one is not important, but the right one contains 4 JTextFields with information of the contact and one JCheckBox that indicates if the contact is a favorite or not. The thing is that I am only able to show the first contact, but I want to be able to scroll between the contacts with a Button that I have in another panel. I think I am actually scrolling among the contacts, but the panel with the information from the contact is not updating the information...

public class PanelInfoContacto extends JPanel{

// -----------------------------------------------------------------
// Constructores
// -----------------------------------------------------------------
/**
* Construye el panel. <br/>
* @param contacto - es una referencia al contacto que muestra. contacto != null.
*/
public PanelInfoContacto(Contacto contacto){
setLayout(new GridLayout(1,3));

[Code] .....

View Replies View Related

JTable With ImageIcon - How To Use Array With 4 Values In Table Cell

Mar 22, 2015

I would like to create a JTable.
 
Each cell contains an array of 4 objects:

[0] ImageIcon
[1] ImageIcon
[2] Number
[3] Boolean

1) Once JTable is displayed, each cell display only [0] .
2) Later, based on user mouse click on cell, cell should display [1]
 
How can I use an array with 4 values in Table Cell?

View Replies View Related

Getting Correct Path When Making ImageIcon - Loading Images To Eclipse

Aug 21, 2014

I am having trouble getting the correct path when making ImageIcon ( i1 ,i2, i3, i4) . I have tried

(this.getClass().getResource("/image/1.png"));
("image/ca.gif");
and
("Users/aritime/Documents/src/ca.gif ");

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class myImageIcon extends JFrame{

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Scroll Image

Sep 30, 2014

I have a java swing application.

1. The human user of my application asks it to fire up a scanner which scans a paper document. The document is a filled in form.
2. The application then displays the scanned image to the human user.The image is displayed in a JScrollPane since it may be larger than the scroll pane.
3. The human user needs to locate a certain item in the form, for example a social security number, and enter it into a field in a data entry screen.Note that the image and the field appear on the same screen.

Of-course the social security number always appears in the same location in the image. Also the image needs to be the appropriate magnification and resolution to allow the human user to easily read and understand the item he is searching for in the image.

What is the best way to present the scanned image to the user such that he immediately sees the item he requires and can enter it into the data entry field.

View Replies View Related

Swing/AWT/SWT :: Why Isn't Image Loading

Jun 20, 2014

I have added the image in the src and bin directories and cross-checked that the name of the image file is correct..Here is the main class

import javax.swing.*;
public class apples
{
public static void main(String args[])
{
JFrame frame = new JFrame();
MyDrawPanel wid = new MyDrawPanel();
frame.add(wid);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(300,300);
}
}

and here is the class that does the image adding part

import java.awt.*;
import javax.swing.*;

public class MyDrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{

Image image = new ImageIcon("b.png").getImage();
g.drawImage(image,20, 20, this);
}
}

View Replies View Related

Swing/AWT/SWT :: JComboBox With Image

Apr 14, 2014

My database contains path of images that I want my jComboBox to diaplay. I have written the following code but it does not work for comboBox but works fine when I display image on jLabel etc. How should I go about this

try {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(updatedetail.class.getName()).log(Level.SEVERE, null, ex);

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Image Not Being Displayed In Jpanel

Feb 19, 2014

Trying to get an image to display in a GUI.

try {
ByteArrayInputStream in = new ByteArrayInputStream(
transferWorker.bOutput
.toByteArray());
BufferedImage bufferedImage = ImageIO
.read(in);

[Code] ....

But nothing is happening in the GUI. I have stepped through and bufferedimage contains the data, but its not being displayed. Whats happening is, an image is being transmitted to serial port of laptop, so i'm taking it in and storing it in a BufferOutputStream and then trying to open it in my GUI class.

View Replies View Related

Swing/AWT/SWT :: Get Image To Show Up On Compiled GUI?

Feb 16, 2014

trying to get my image to show up on my compiled GUI.

Here is my GUI, I just need to know how to get the image to show, where do I save an image file so that it comes up in my GUI.

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

[code]...

View Replies View Related

Swing/AWT/SWT :: How To Load Image To JFrame

Jul 23, 2014

How to load an image to a swing application?? I want to load it to myframe(JFrame)..

View Replies View Related

Swing/AWT/SWT :: How To Update Image In Java GUI

Jul 10, 2014

I have a GUI with several buttons and I'm using NetBeans GUI Builder to do. At the click of one of these I would like for it to open another frame containing a picture. So I associate a listener (actionPerformed) the button and when clicked it opens actually post the new frame.

In the new frame I waxed a JLabel and then I associate the image of the label. I saw that to do that NetBeans generates this code:

label.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/tree.png")));

My problem is that the picture is overwritten several times during the execution of the program is not changed yet in the frame. That is, in the new frame is always displayed an old version of the image.

I have an image that is created every time I click on the button (it always has the same name and same path). Basically I have a generic tree on which I perform the operations (add, remove, etc..). When I click on the button I call a method that generates the image of the tree (using Graphviz). So I have one image that changes over the time...

How can I do so that the image is always up to date?

The Code:

package View;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public class AlberoIpotesi extends javax.swing.JFrame {

[Code] ....

View Replies View Related







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