yconic - CompSci Question...
Hide Menu

My Feed Money for School Student Help Brands Winners Support Center



Explore yconic
Explore Student Life Topics
Scotiabank
STUDENT CHAMPION
yconic proudly recognizes Student Champion Partners who are providing our community with superior support for their student journeys. Learn More
Student Help Brands

CompSci Question...

A photo of newageanubis newageanubis
I have a programming-related question that I thought the engineering, mathematics and computer science hopefuls here would be able to help me with.

I am currently working on a project in the Java language for ICS4U at school. It is a GUI development-focused project. I am using the NetBeans IDE and the Java Swing API for GUI design.

I have a list of items, and beside them are buttons that are used to work with the list (e.g. add item, remove item). I need some buttons to be disabled when there are no items in the list, or when an item is not selected. Having these buttons enabled in those situations allows for a runtime error to occur if they are pressed.

How do I make my program listen for when the list is empty, or when nothing is selected? What event listeners should I use?
Was this helpful? Yes 0
8 replies
 
A photo of jelly jelly
Can't you just compare your labels beside the buttons to everything on your list? Then set enable to true/false from there? Could probably easily make a for loop considering that your list is in an array... I don't think I'm understanding the program properly. What's the runtime error anyway?
Was this helpful? Yes 0

 
A photo of newageanubis newageanubis
I'm using DefaultListModel to display the list contents and JList to allow for selection. Sorry for not mentioning that. The runtime error is that a NullPointerException (because there is no item selected) is thrown and the program crashes. I could catch the thrown exception, but this could only occur after the exception is thrown (button is pressed). It makes more sense and looks better if the buttons are disabled in those two situations.

The only non-property related code that can be invoked when the GUI frame launches must be an event handling method (e.g. actionPerformed). This must be accompanied by an event listener to "listen" for when the event for which the event handling method is written occurs. That's why I was wondering what listener I could use for when the list is empty, or when nothing is selected.
Was this helpful? Yes 0

 
A photo of greygoose greygoose
Just fyi, this is *not* a computer science question. It's barely even a programming question--gui development is very cut-and-paste.

I don't mean to sound like an ass; if this was actually a computer science question I could help you with it. But the problem is that most high schoolers seem to be under the impression that programming, especially mudane stuff like this, is computer science. It's not. By the way, if this is stuff you're interested in for a career, save yourself the money and stress of university and go to a tech school.

For an idea of what computer science actually is, go look up these concepts on wikipedia:
- binary search
- binary tree
- stack data structure
- "big-O" notation
Was this helpful? Yes 0

 
A photo of trollhunter trollhunter
grey goose you arent very polite try giving the kid a break
Was this helpful? Yes 0

 
This post was deleted

 
A photo of greygoose greygoose
Stating the fact that this is not a computer science question I wouldn't call bashing. The reason I preemptively apologized for potentially "sounding like an ass" was because I was worried the guy might take offense to calling the development of graphical user interfaces "cut-and-paste." I didn't intend to insult his ability--I was trying to say that he's doing it wrong, to some extent. The best gui code you'll write will be something taken pretty much verbatim from a polished interface, so usually the best idea for these things would be to search the internet for some examples.

Also, I am sick of all the people going into comp sci that want a programming degree because universities sucked at telling them what the programs actually involved. These people would be far more suited for a software engineering degree or an IT program. I'm trying to do my part in shattering the misconception so people don't make the wrong decisions.

To be honest, that handful of concepts I mentioned are easily understandable by a high schooler with a little bit of calculus, if they are willing to think about them a bit. A starting point, as I said. Or should I be referring this guy to the X11 and OpenGL manuals for graphical development when he's having trouble with a button? Send him towards the study of advanced algorithms, operating systems, and compilers in his time of need? You too ought to consider having some reasonable expectations. :P

I've met people long graduated in the workplace in development that had not a clue what a binary search was, and wouldn't be able to perform any modular arithmetic outside of mod-2 (odd/even). The amount of actual CS background people working in development have varies wildly.

Oh, I should mention, Eclipse is the golden standard for the Java IDE. You may want to take a look into that.
Was this helpful? Yes 0

 
A photo of engineersrock engineersrock
Ya, Eclipse is really great. It really makes your programming experience much better. :)
Was this helpful? Yes 0

 
A photo of iRamie iRamie

@greygoose wrote
Just fyi, this is *not* a computer science question. It's barely even a programming question--gui development is very cut-and-paste.

I don't mean to sound like an ass; if this was actually a computer science question I could help you with it. But the problem is that most high schoolers seem to be under the impression that programming, especially mudane stuff like this, is computer science. It's not. By the way, if this is stuff you're interested in for a career, save yourself the money and stress of university and go to a tech school.

For an idea of what computer science actually is, go look up these concepts on wikipedia:
- binary search
- binary tree
- stack data structure
- "big-O" notation



^THIS


@trollhunter wrote
grey goose you arent very polite try giving the kid a break



Some people don't even know what computer science is and intend to go into a university program without any experience whatsoever. I think you can see where im going with this, and its just sad..
Was this helpful? Yes 0