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


ADVERTISEMENT

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

Swing/AWT/SWT :: Unable To Show Image When Click On Button

Oct 21, 2014

I've recently decided to learn Java on my own using internet material such as forums, blogs and you tube. Ive never programed before but through some research I concluded that Java is going to be on the mid spectrum of difficulty as far as verbiage goes. I ma in no way implying that Java is easy but instead closer to spoken English that c++ if my research is correct. So here is my attempt at a basic program where I click a button and it will make an image appear. Not sure where Im falling short

package clicktoimage;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Clicktoimage extends JFrame {
private JLabel label;
private ImageIcon image;

[Code]...

View Replies View Related

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 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 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

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

Putting ImageIcon Into Label (Original Size) By Clicking On Label (Thumbnail Created Before)

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

When Click On New Button / All Icons Except Button Just Clicked Don't Display

Oct 16, 2014

The gist of it is to create a very basic memory game. There are 12 buttons, each associated with an icon. Every button that you click will display the icon and will stay there until clicked again. I got the bulk of it taken care of, but my issue lies with switching the icons back and forth. I can get them to display one at a time, but when I click on a new button, all the icons except the button I just clicked don't display. Essentially, only one shows up at a time.

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.SwingConstants;

[code]....

View Replies View Related

JSF :: How To Make Focus To Button During Onload If Button Is In TabbedPane

Feb 24, 2015

I am using JS, how we can make focus to a button during onload, the button need to get focus which is in tabbedPane tab Name : (Search Critera1) using javascript.

View Replies View Related

How To Get Which Button Clicked In Through GetActionCommand When Button Have No Label

Sep 16, 2014

I have a JButton with a .PNG icon on it. I want to get that button click in actionPerformed Method but Jbutton have no Label... How i will know that which button clicked?

View Replies View Related

Swing Button That Creates A New Button

Nov 29, 2014

I am creating a mad libs type program. This section of code is for the user to be able to make their own mad lib template (that people will be able to fill out later). The normal blanks in a mad lib are for verb, noun, adjective, adverb, etc. I cam up with 13 or so of these buttons, but it would be nice that if the user wants to add a button that they think we missed, such as 'Person in the Room' or 'Silly Location'...that the user would be able to do this. I sort of pictured there being a button that says 'add button' or something like that. Is there a ways to do this with the way I've set things up?

public class MadLibs {
public static void main(String[] args) throws IOException {
////////////////////
//TEXT PANE WINDOW//
////////////////////
//Set up a JTextPane object : The JTextPane is a specialized form of the JEditorPane
//designed especially for the editing (and display) of styled text.
final JTextPane pane = new JTextPane();

[Code] ....

View Replies View Related

How To Compare Strings

Mar 13, 2014

Its supposed to notify the user if they have a palindrome, but keeps returning true even when I type, "hello".

import java.util.Scanner;
public class PalinDrome {
public static void main(String[] args) {
String line;
Scanner input = new Scanner(System.in);
System.out.print("Please enter a word ");

[code]....

View Replies View Related

JSF :: How To Compare Two Variables

Feb 25, 2014

Having two values

<c:set var="var1" scope="view" value="#{ID1}"/>
<c:set var="var2" scope="view" value="${ID2}" />

I tried in <c:if test=${var1 == var2}>

and eq also

above condition is not working. Both are same object. How to check?

View Replies View Related

Trying To Compare Two JComboBox

Jul 23, 2014

I'm trying to get the input of two jcomboBoxes for example if jcombobox 1 option 1 and jcombox box 2 option 1 is selected result = x

Here is my code:

comboDest1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
//
// Get the source of the component, which is our combo box.
//
JComboBox comboDest1 = (JComboBox) event.getSource();

[Code] ....

How would i achieve this?

View Replies View Related

How To Compare Date

Jun 17, 2014

how can i compare date with following request the value date transction must be within the Active date(>= greater than or equal) and inactive date(<= less than) date range

View Replies View Related

How To Compare Double

Jun 17, 2014

how can i compare two double values is this correct

Java Code:

public boolean isEqualToD(double s_src, double s_compareTo)
{
boolean flag = false;
try
{
if(s_src == s_compareTo)
{
flag = true;

[code]...

View Replies View Related

How To Compare Objects With Another

Feb 3, 2014

I have the following method stubs to complete:

public class Item{
private int myId;
private int myInv;
public Item(int id, int inv){
myId = id;
myInv = inv;

[Code] .....

I do not understand how to complete the compareTo() method and the equals() method. I understand that the compareTo() to should return 1 if the argument is smaller -1 if its bigger and 0 if they are the same, but I do not understand how it's possible to compare the current object with the object passed in as the parameter.

This is what I tried for the compareTo():

public int compareTo(Item other){
return this.compareTo(other);
}

But my compiler tells me its a recursive call so I am not sure if I am doing this correctly.

Basically I am supposed to compare an object to another but I am not sure how to access the object that is not passed in as a parameter and compare it. Same goes for the equals(). This is what I tried for that (compiler also says its a recursive call):

public boolean equals(Item other){
return this.equals(other);
}

View Replies View Related

How To Compare String In If Else

Feb 10, 2009

how do i compare string in if else ?

cos if i do these, it get an error of

Comparing string using == or !=

if(carModel == "Honda") {

car.setCarID(1);

car.setCarModel("Toyota");

car.setCarDescription("Powered by VVTi Engine");

car.setCarTransmission("Auto");

car.setCarPrice(56000);

View Replies View Related

Compare Two Circles

Apr 26, 2015

Circle class:

public class Circle extends GeometricObject implements Comparable<Circle>
{
private int radius;
public Circle(int newRadius)
{
radius=newRadius;

[Code] ....

When I run the driver class it tells me that all tests have passed(as it should be) except for Test 0. I have tried to play around with the code, but I cant figure it out and it is driving me crazy because in my head my code makes sense.

View Replies View Related

How To Compare Two Date

Feb 18, 2014

how can i compare two date in between in java

View Replies View Related

Compare All Objects In ArrayList To All Others But Not Self

Mar 15, 2015

I have a ArrayList of objects of class called HockeyPlayer (ArrayList<HockeyPlayer>). A HockeyPlayer has a String name and int number of goals.

This is my current work for comparing each object in the list to every other and printing them to screen:

Iterator<HockeyPlayer> it = hockeyPlayersList.iterator();
while (it.hasNext()) {
HockeyPlayer singleHockeyPlayer = it.next(); //the first one encountered
// HockeyPlayer nextHockeyPlayer = it.next(); //the next one encountered

[Code]...

This of course produces some duplication in the print-out: These are the equal hockey players: Who Ever wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

Jason Harrison wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

These are the equal hockey players: Jason Harrison wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

Who Ever wears jersey. This type of employee is paid: true. This employee has post-secondary education: false. This employee's work is to play. This hockey player has scored 0 goals.

How do I remove the duplication in the print-out?

View Replies View Related

Compare Int With Array Of Values

Dec 24, 2014

I need to compare an int with an array of values generated with a for loop previously. I have something like that for the search..

for( int i = 0; i < 5; i++){
System.out.print("Indovina.. inserisci un valore: ");
// I memorize the value taken input
n = sc.nextInt();

[Code] ....

Also, I need to print the array each time I insert a value that is in the array. But, hiding the values still not "guessed".

View Replies View Related

Compare First Characters Of Two Strings?

May 20, 2015

I am trying to compare the first characters of two strings.

import java.util.Scanner;
public class testIf {
public static void main (String [] args) {
String userInput = "";
char firstLetter = '-';

[Code] .....

in the if statement i get this error Cannot invoke charAt(int) on the primitive type char...

View Replies View Related

Compare Session Value With Textbox?

Oct 2, 2014

I could get my session values in my jsp, now I want to compare the session value whether it matches the textbox, if it matches, it will redirect the user to another page else it will remain the same page.

View Replies View Related







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