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
ADVERTISEMENT
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
View Related
Apr 5, 2015
I was wondering if its possible to show a video (mp4) inside a jframe? like the windows media player ....
View Replies
View Related
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
Apr 27, 2015
I have tried to add a scroll bar line 28 - 31 and can't figure out why its not working. Its not even showing the scroll bar!
public class TheFrame extends JFrame {
private static ThePanel canvas;
private String deckImagesToUse;
/**
* The constructor creates a Frame ready to display the cards
*/
public TheFrame(String cardImgFile) {
[Code] .....
View Replies
View Related
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
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
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
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
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
Jun 22, 2014
So I have this line of code...
ioexception11.addChoosableFileFilter(new Jframe());
And when I compile it gives me...
error: constructor Jframe in class Jframe cannot be applied to given types;
ioexception11.addChoosableFileFilter(new Jframe());
View Replies
View Related
Apr 5, 2014
I have written some error checking code
File name ErrorPage.jsp
<%@ page language="java" isErrorPage="true" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Error</title>
</head>
[code]...
I have put error.jsp and badpage.jsp file in public access folder that is web content in eclipsewhen I am running the code I am status code of 500 and not the errorpage.jsp message .
View Replies
View Related
Nov 6, 2014
I'm doing a software Java GUI - JFrame form like this:
1. The user wants to click on a button that opens a bunch of images that will be displayed as thumbnail in the bottom of the JFrame .
2. Then the user wants to select/click one of the thumbnail and make appear the corresponding image in it's original size on above(center) of the JFrame.
For doing this I used 3 JPanel.
One contains a JButton that opens the jfilechoser dialog window,
the second "panelPreview" is for putting the thumbnails created,
and the third "panelGrande" is for the image in it's original size.
The firs part "1." is ok.
But in the second part : I got one error when I want to put the ImageIcon in to the JLabel with the further intent of displaying it.
lblBig(imgIcoVett[i]);
In this project I'm dealing with arrays of ImageIcons and JLabels, so it's a bit advanced level for me, so I'm not sure that I wrote right the part of the MouseListener too.
The error displayed by netbeans says "cannot find symbol symbol: method lbl (ImageIcon) local variables referenced from an inner class must be final or effectively final"
Here I attach the project I did with netbeans"AAAD Unlayout 2.zip", but if you just need the highlight of the code, here it is too:
private javax.swing.JButton btnOpenfile;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lblBig;
private javax.swing.JPanel panelGrande;
private javax.swing.JPanel panelPreview;
[Code] ....
View Replies
View Related
Jan 23, 2015
how we call a jFrame from another jFrame .
View Replies
View Related
Jan 18, 2014
I am working on a program to have a user input two positive integers and then finding the greatest common denominator between the two. My problem is, I don't know how to display the number (num2) that is returned after the method. Putting a simple System.out.println gives me the error "unreachable code".
import java.util.Scanner;
public class ****
{
public static void main(String[] args)
[code]....
View Replies
View Related
Jun 19, 2014
My program task is if we give a character... the display will print CHARACTER AS CHARACTER Shape
IF WE GIVE LETTER L... IT WILL PRINT LIKE THIS...
L
L
L
L L L L
View Replies
View Related
Feb 10, 2015
I have a problem with one method for my assignment. This is the requirement for this method: "This method uses a loop to list all accounts contained in the Array, adding each account details to a String, before outputting to screen in the format specified in the screenshot below. Ensure that there are no out of bounds exceptions by checking if each array slot has an account object before adding its details to the output String. (arrayname[index] != null)"This is my code for this method:
public void listAllAccounts() {
String allAccountsString = "List of all accounts:
";
for(int i = 0; i < ACCOUNT_SPACES; i++) {
//allAccountsString += accountArray[numAccounts];
if (accountArray[i] !=null) {
allAccountsString += accountArray[i].toString() + "
" ;
}
}
JOptionPane.showMessageDialog(null, allAccountsString);
The problem is that the Message Dialog does not display the accounts I have already created. It just displays "List of all accounts:
";
View Replies
View Related
Mar 27, 2015
When i am trying to display the contents of this array its showing arrayindexoutofbounds exception...how do i display this array?
<%
String names[][] = new String[10][2];
for(int i=0;i>=10;i++){
for(int j=0;j<=i;j++){
names[i][j]="anu";
if(j>0){
[Code] .....
View Replies
View Related
Sep 20, 2014
I created a instance of a class AddItemView, inside StartUpMenuController. I then passed it into the class, the main method is below showing that as well. However when I do this:
else if(e.getSource()==menu.addBtn)
{
new addItem();
}
I get an error, little red line on the bottom of the text. I am testing the frame at the moment to make sure it is what I want before I move on to the Controller side of it. I just want to display it and go from there.
package mainMenu.Home.DataBase;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import addItemBtn.Home.DataBase.AddItemView;
public class StartUpMenuController
{
StartUpMenu menu;
AddItemView addItem;
[code]...
Not sure if this is the issue but the class I am making a new instance of is in a different package. I imported the package though.
View Replies
View Related
Aug 21, 2014
I am trying to display the files stored in server using jsp. I used the code below to display. But for pdf it is asking to download (No option for open). For XLS, XLSX, DOCX, PPT and PPTX it is showing zip file to download. For type doc it is showing junk data.
<%
String fileName=(String)request.getAttribute("fileName");
int loc = fileName.lastIndexOf(".");
String fileName1 = fileName.substring(0, loc);
String fileName2 = fileName.substring(loc + 1, fileName.length());
[Code] ...
View Replies
View Related
Sep 14, 2014
One of my official site is not disaplying the content in machine#1 IE10 browser.And the same site is showing data in another machine#2. I compared the both machines JRE and JDK settings but no difference found.
how to link the JRE to browser.
View Replies
View Related
Oct 13, 2014
so far this is what i have written. The program works correctly but I need to be able to have the numbers i am entering to show up on the .txt file.
import java.util.Scanner;
import java.io.*;
public class LargestAndSmallest {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
[code].....
View Replies
View Related
Jul 11, 2014
I'm learning about inheritance and part of my problem is to create an Order with methods, then an UpdateOrder where the total price is changed by adding four dollars to it, and then a main method displaying a few orders. I've copied all three below in order. My question is when I run the program it will display the totalprice() first for the second order followed by name, number, etc.what you override always displayed first regardless of the order you put them in? (The issue is at line 31 on the third code.)
import javax.swing.JOptionPane;
public class Order { //superclass
private String customerName;
private int customerNumber;
protected int quantityOrdered;
protected double unitPrice;
protected double totalPrice;
[code]....
View Replies
View Related
Feb 28, 2015
I need to display my calculations in a table format using loops.
//Imports
import java.util.*;
import java.text.*;
public class YourLoanCalculator {
[code]....
The increments are correct, but I wanted them listed under the "Payment #:" column. I figure that if I do that, I can also correctly display the interest, principal, unpaid balance and total interest paid at that point, right?
View Replies
View Related
Jan 28, 2014
Aatrox
Champions@3622e177
Champions@4805e9f1
Champions@57e40274
Champions@354124d6
Champions@262f4813
Champions@64f01d52
Frozen Heart
Randuin's Omen
As you can see instead of displaying the champion name it is displaying the memory location and I do not know how to fix it.
class Champions
{
String name;
Champions [] weak = new Champions [3];
Champions [] strong = new Champions [3];
String [] items = new String [3];
public static void main (String [] args)
{
[Code]...
View Replies
View Related
Jan 20, 2014
Here is my code
Java Code: //Points Display
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Dimension;
import java.util.Random;
[code]...
1. Why, when I press "New" rapidly, will it skip painting shapes sometimes/adding to totcount.
2. How can I make it so that The box in the background(which is currently connected in the wrong way as I was getting an error when I connected it correctly) can be modifiably large. AKA, I want to draw a grid in the background that can be different sizes, depending on the values of a variable xsize and ysize.
3. What can I do to clean this up? All I want it to do is display the convex hull of the four points given in the int[][] displaypoints.
View Replies
View Related