wayne morton

Greenhorn
+ Follow
since May 17, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by wayne morton

I create a GUI with 10 check boxes but these check boxes are from an array and all have the same name.e.g.



I tick box 4 and i want it to tell me which box i have ticked...how do i get that reference so can get the label to read out "You have ticked box 4"?

I can get it's reference in the sense that it says test, but they all say test, so which test box did you tick?


The obvious solution is to make the for loop give them all a different name.e.g.test1, test2 etc but they all have to have the same name because in the real instance of what i am doing i have a tabbed pane and on clicking "New Tab" it creates a replica of the existing tab so checkbox[1] in in tab 1, checkbox[2] is in tab 2 etc and when i tick a box i need to makes it's actions relevant only to that tab.
11 years ago
Thanks for the link Dennis, that looks interesting.

The experience, especially of the different ways something can be achieved is most of my problem as i have only really just begun to delve into the world of java and thus am limited to working with what i have learnt up to now and making the best of that when creating programs. Having said that i appreciate when people point out better or alternate ways to achieve my goal as that increases my scope of learning and points me in new directions to improve my knowledge, although that can often be a struggle as it is often assumed that i know what they are talking about.i.e. i have been thinking in the wrong way rather than me simply not having encountered that alternate way yet.
11 years ago
In chronological order:-

XP was and is a great OS and when i still occasionally use it it feels like an old friend.

Vista was atrocious and i spent many extra years with XP because vista was so bad. I postponed buying a new PC because of vista and when i eventually had no choice i immediately removed vista and installed XP on my new PC. Any time i had to/have to deal with it i get that sinking feeling before i even start and it gets worse as i use it.

I fell in love with w7 from the first time i had chance to play with it. It just felt like the natural successor to XP. It felt natural and the shiny bits were actually useful rather than seeming like an exercise in what could be done.

Having some minor experience with w8 i get the feeling it is going to be a bit of a vista. In certain circumstances it is good.i.e. where the touchscreen facility is basically a requirement, such as factory floors/production lines and as has been out for a while on phones, although the phone version is not really that great.
When it comes to your general user.i.e. someone who is using it as a PC and not using the touchscreen it is fiddly and unnatural as it is obviously designed for touchscreens, seemingly at the expense of any other interface.
So my conclusion would be if you use/wish to use touch screen a lot then w8 will probably be a great help, if not then stick with w7.
11 years ago
Thanks for the replies.

The word assume was probably a wrong choice to use but in the context of the whole which was as a question i thought it would be clearer that i was guessing because i had tried to find what was causing the null by using print statements after every line and nothing was showing null up to the point of the error, and then after the error there was no print statement as there was an error which interrupted the code. I even removed the code which caused the error and allowed the code to carry on, still using print statements and everything was as expected so there was just an error at those points, so my only conclusion was that i wasn't creating the array in a form that the comparator could understand which as i have now got it working, seems to have been born out to be true?

People have suggested using an object instead, but as i already said i am learning and basically have no idea where to start in that regard and i have tried searching for it with little success as, i guess what is due to normally the case, i don't even know what terminology to use to find what i am searching for. Hence i have done what will likely be an inefficient and dirty workaround and got it working. That workaround is creating a hard copy array (as in the original working version of the code) and then modifying it with the second version which didn't work by itself.i.e. a combination of the two methods i used in my original post.

Unless someone is willing to at least point me in the right direction of how to create and use this object that has been mentioned it is going to stay that way as just telling someone they should be using something is like telling someone who can't drive that driving a car would be quicker than walking.
11 years ago
As i am still learning and this is my first foray into sorting a multidimentional array, you couldn't give me an idea of how to set that up?

In regard to the null, which i have been looking for, as i mentioned i have put in a separate System.out.println() method in between the creation of the array and the array sort and all elements are present so my only assumption would be that my comparitor can't understand the array when i build it that way although it works fine when i hard build it, setting the elements as a set array?
11 years ago
As you may have guessed from the title i am trying to sort a two dimensional array, now in general i can do this.i.e. with a set array that i create.

From playing with my current code it would appear that when trying to do this with a custom created array based on variable data input i get a NullPointerException error.

So a short example of the code that works:-




And the code i am trying to use:-


The error code i get is
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at ColumnComparator2.compare(CalculateData.java:170) In the example code it relates to line 41
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:329)
at java.util.TimSort.sort(TimSort.java:203)
at java.util.TimSort.sort(TimSort.java:173)
at java.util.Arrays.sort(Arrays.java:659)
at CalculateData.actionPerformed(CalculateData.java:138) In the example code that relates to line 18
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
at java.awt.EventQueue.access$000(EventQueue.java:102)
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:676)
at java.awt.EventQueue$4.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)


From what i can tell the array is created but the sort/comparator is reading it as null but there are elements in the array at that point as i have used a system.out.println() to check.

I am guessing it is to do with the way i am creating the array.e.g. is it not really a two dimensional array?









11 years ago
Thanks for the reply Paul. It would seem for future reference that using Properties is not the ideal way so i will look at other ways for transferring data in future, for now having it ordered would have just been nice rather than any form of necessity.

Thanks for moving the post also, i thought i put it in a different section than i did.
11 years ago
I am starting to play with XML files to store my data and i was wondering if someone could explain to me the logic behind the way it adds information to the file.e.g. i have this simple little code


All works fine apart from the order it stores the information in the file.i.e. the XML file looks like this

Why does it store the data in that order and not a, b, c?
I would prefer it did a ,b ,c rather than b, a, c, mainly for clarity reasons when i am checking it has stored the data properly and the first step towards that goal is understanding why it prints in the order it does.

I guess my obvious next question is tips for ordering it or where to find information on how to order it?
11 years ago
Thanks for all your help Steve.
Initial testing seems to work as required in regard to simply importing from an XML file. As per usual it's knowing which direction to look in is the hard part

I really appreciate the followup and I'll certainly look more into those libraries that ship with java as (for learning purposes at least) i would rather learn with the basic tools first and then maybe move onto external tools once i have the basics figured out in case for some reason in the future i can't use an external tool and i always have the basic tools to fall back on if needs be.
I have a small program which creates an xml file



Now i wish to call an element of that file and display it.e.g. the username.

After searching seemingly endlessly for a way to do this with the basic java libraries the only answer i seem to get is use an additional open source library. I would prefer to know how to do it with the existing libraries if only for learning sake but eventually giving up on finding reasonable info on doing so i chose XOM as it is used in a book i am using and am now trying figure out how that works and as per usual most 'tutorials' are designed for people who know quite a bit about what their doing, which i obviously don't...

This is about the closest to my current understanding of how it should work

import java.io.*;
import nu.xom.*;



root shows properties as expected, name shows null?
What argument am i meant to give to retrieve that element so the readout would be "rcade"?

Or preferably how do you retrieve it using the basic libraries?
Thanks again Jelle.

I already incorporated revalidate() and repaint() into the logic.
After some testing previously i found that adding both methods was the best option as depending on the setup one wasn't enough due to either not working at all or not working as intended.i.e. making a bit of a mess of my layout on updating it.
11 years ago
Thanks for the reply Jelle.
From my basic description a card layout would seem like a logical piece of advice but from what i understand about card layouts it simply a system of tabs unless it is more complex that i perceive? Which is not what i want for this instance. In this case i need to be able to see multiple inner panels at the same time for easy comparison, not to be flicking between one pane and another which i would have to do with tabs.

In the case of what i have created there can be multiple inner panes with varying data for comparison and will eventually organize them.

Baring what is the best layout design my main question was to do with the best way to delete a panel and its contents which is useful for future reference at least.

In simple terms when deleting a pane can i just delete that pane itself or do i need to specifically delete all it's components also to prevent any future issue?
11 years ago
Brief explanation....I have created a GUI with a scroll pane, an add button and delete button.

When you press add it creates a new pane within the scroll pane and that pane contains various components, labels, text fields etc.

When you press delete it obviously deletes that new pane and all it's components.

Now my question is can i just use


which i am currently using and appears to work although i am concerned that this may cause issues as i have not individually removed all the components? Do they still exist and does that give potential to cause issues when i create them again?
At the moment it seems to work fine.

Or is it best to remove all components at the same time.e.g.

Or is that just being pedantic and creating unnecessary work for myself?

11 years ago
That's great information. The tutorial is particularly useful.

Thank you both for your help.
11 years ago
I am attempting to have a JcomboBox with a list of ranks to choose but i would like to have a small picture of that rank alongside the text.

I can get the text as an option, i can also get a picture as an option but not both at the same time.

I guess the obvious question is, is it possible in the first place as all the examples i have found appear to have the picture output as effectively a separate window attached to the JComboBox?

The basic idea i have been trying is




The result is
RookieRookie.gif
appears in the JComboBox.i.e. the string and then the file reference rather than the picture itself.

Any pointers on how this could be achieved would be appreciated.

Thank You.


11 years ago