• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Mouse shift event coding - to trigger a predetermined sequence of images to a GUI

 
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Simon Evans:
Dear Campbell Ritchie, Joanne Neal & programmers

I have changed the relevant line in program 'Tarot' to:

for (int i = 0; i< images.length; i++)
{
images[i] = new ImageIcon( + i + ".gif");
};

******************You mean "" + i + ".gif", surely.

I have tried putting the text:- javac -version

to the console, but get:-

javac: invalid flag: -version

along with all the other associated gen that follows such returns.

***********************It always works for me, although I couldn't find "version" on the javac home page.

I tried this instead of those three columns of repeated code, ie:-

for (int i = 0; i< 41; i++)
{
JLabel[i] = new JLabel(images[0]);
p.add(JLabel[i]);
JLabel[i].addMouseListener(mousie);
}

but this got me :-

C:\Java\Java Six>javac FT.java
FT.java:21: cannot resolve symbol
symbol : variable JLabel
location: class FT
JLabel[i] = new JLabel(images[0]);
^
FT.java:22: cannot resolve symbol
symbol : variable JLabel
location: class FT
p.add(JLabel[i]);
^
FT.java:23: cannot resolve symbol
symbol : variable mousie
location: class FT
JLabel[i].addMouseListener(mousie);
^
FT.java:23: cannot resolve symbol
symbol : variable JLabel
location: class FT
JLabel[i].addMouseListener(mousie);
^
4 errors

C:\Java\Java Six>

****************You have got an array the same name as the class JLabel. Try changing that, maybe to labels[i]. Make sure the scope of that array and of "mousie" are correct.

I have recoded program NameInput in accordance with Joanne's diagnosis, thank you.
re:-

****************Which classes from java.util are you using? I think you might be able to lose that import.

Thank you for your help.
Hoping to hear.
Yours
Simon.

 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You usually need more parameters than that for the JOptionPane.showSomething methods. Please have a look at their API. If you don't have a Component to use as the first argument, try "null".
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Campbell Ritchie,

It was to :

I changed the code to, but I thought that was what you were suggesting I do when you said such a line would give an empty opening character

with :

but I will change it back, as that was not the case. If it runs okay with the " " on the jdk1.4 then as you said, there must be something
amiss with the jdk1.6 on my computer (rather than with the program).


The main difficulty I have with compressing class 'Tarot' is with the instancing of the Jlabel label [] array. I am not sure of the necessary
syntax for this step.

I have tried :


but this returns:-


C:\Java\Java Six>javac FT.java
FT.java:21: ';' expected
JLabel[] label = new JLabel[i](images[0]);
^
FT.java:21: not a statement
JLabel[] label = new JLabel[i](images[0]);
^
FT.java:21: ';' expected
JLabel[] label = new JLabel[i](images[0]);
^
3 errors

I don't know if you could suggest the right syntax for the first statement in the loop.

Is there a tutorial out there that'd deal with such a procedure?

I realise I could remove the java.util import statement from the program NameInput. The program might need it later on as it is at an early

stage at present. In fact its development depends on finding the right way to initialise array label, ie: making an outer for do loop with

array userNames[i], and an inner for do loop with array userNames[i].length() to instantiate the JLabel[]label array.

Thank you for your help.

Hoping to hear,

Yours
Simon.
 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to learn how to initialise an array. Look at this part of the Java Tutorials. And there is a difference between " " and "". You probably need "" + i + ".gif" rather than " " + i + ".gif".
 
Simon Evans
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Campbell Ritchie,

I realise I ought to have instanced the JLabel array before beginning the loop that populated its index with the images array, and
have coded it (program FT) accordingly.


I have put the MouseListener object 'mousie' argument pass to label objects method call of addMouseListener() in another loop, from where it

can recognise its object.

As it is the program compiles, but it doesn't produce anything whence run - it might again be my jdk, would you be able to try it out on your

machine?

Thank you for your help.

Yours

Simon (code follows:-)

 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem has something to do with loading the .gifs. If you try to get a URL object from "23.gif" it consistently returns null. There is something wrong with the path supplied to get the .gifs into your JLabels.

Don't know what, I am afraid.
 
Simon Evans
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Campbell Ritchie,

I was wondering if the code to program 'FT' is okay, not withstanding the problem with the gifs?

I tried running it on my other computer (which is running okay now) and got the same result, ie: nothing, although that computer runs program 'Tarot' - which is the same except for the loops to reduce repeat coding.

I therefore take it that the problem must lie with the code, where have I gone wrong/where do you think I could go right?

Incidentally I put the program 'Establishjdk' to other computer, now it is working, and it returns:- 1.4.2_04

Hoping you can help.

Yours

Simon.
 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do have to do things like adding the Panels to a Frame, otherwise you can't see anything; I put some debugging code in and the Timer seems to be working, but I kept getting null URL from the getClass().getResource() calls, so I suspect there is something going wrong with finding the gifs. But I know next to nothing about finding gifs, I am afraid.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it could be that your problem is here
images[i] = new ImageIcon( "" + i + ".gif");

the image files from the tarot card link are .jpg

try it as
images[i] = new ImageIcon(i + ".jpg");//also, you don't need the leading ""
 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"gif" rather than "jpg"? What a daft thing for me to miss.
[ September 05, 2008: Message edited by: Campbell Ritchie ]
 
Simon Evans
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Campbell Ritchie,

Of course - you are right, I've changed the code to the below and it works on my jdk1.4 alright, obviously with a fraction of the amount of code, too.

So long as it works, it doesn't matter which jdk I am running it on, as far as I'm concerned.

Dear Michael Dunn,
I altered the downloaded jpgs to gifs in Photoshop, also changing the sizes to about 1cm across to 2 down, or thereabouts.

The marseilles pack is the best one to use, to my mind, at least.

Thank you for your assistance.

Yours

Simon

(code follows:-)

 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it really working? Well done.
 
Simon Evans
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Campbell Ritchie and all other programmers,

I wanted to elaborate on the program Tarot (or GypsySpread) with NameLayout that I put up earlier so that it'd reiterate for the number of times that the method length() returned, hopefully this reiteration would be of the instancing of a new JLabel and the outer loop being dictated by the initialisement by variable Names would instance the new JPanel - for the userNames.length() value (ie that of the labels) to be placed in.

Thus anyone's name input would generate a gui with a row length corresponding to the lengths of their names, and columns corresponding to the number of names input to the JOption pane.

Anway, in trying to change the string value returned of line:-

System.out.println(usersNames[i].length());

to get an int that can be used in the reiteration that'll instance the labels in a subsequent

for(i = 0; i< Names; i++) loop, I tried to parse the value userNames[i].length() to create an int to put into another - this time numerical array, but the console doesn't recognise the parseInt() method anymore - so anyhow I am a bit stumped, reckoning as I had, that a class method such as parseInt was recognisable throughout any program.

Could you point out where I am going wrong?

Thank you for your help.

Yours

Simon (code follows:-)


Gives :-

C:\backup\Project Tarot Two>java NameLayout
5
5
5

to input to JOption pane inputs of 3, Simon, Angus, Evans.




Compiler returns :-


C:\backup\Project Tarot Two>javac NameLayout.java

C:\backup\Project Tarot Two>javac NameLayout2.java
NameLayout2.java:24: cannot resolve symbol
symbol : method parseInt (int)
location: class java.lang.Integer
int namelength = Integer.parseInt( usersNames[i].length());
^
1 error

C:\backup\Project Tarot Two>
 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read what you are printing out to get "5". And you are passing the same to the parseInt() method.
 
Simon Evans
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Campbell Ritchie,

I see what you mean - the method readlength() returns an int so doesn't need parseing.

It has occurred to me that this thread is getting quite long, and might be getting buried under the previous 50 or so posts, so I've started another thread that is more to the point - I think I no longer have to ask about the mouse enter/ exit action listener - as that part of the program is no longer presenting a problem.

Thank you for your help.

Yours
Simon.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent application. The most important thing is interesting and simple. Thanks to the author.
 
Campbell Ritchie
Marshal
Posts: 80506
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic