checkbox

Hello all

I'm having problems with a checkbox and a button. I want that when i click on the checkbox, the button is set to Enabled, and if i uncheck the button is set to disabled again. When the applet starts the button is disabled by default, and the checkbox is unchecked. Here is my code so maybe you guys can tell me what is wrong.

privatevoid NuevoActionPerformed(java.awt.event.ActionEvent evt){

if(Nuevo.equals(true)){

Ingresar.setEnabled(true);

}

else{

Ingresar.setEnabled(false);

}

}

[945 byte] By [River_Platea] at [2007-11-27 9:25:06]
# 1

Well, I suppose Nuevo is the name of your JTextBox. If it is, I suppose you meant to write: Nuevo.isSelected() instead of Nuevo.equals(true). You could, actually, shorten this code even further:

private void NuevoActionPerformed(java.awt.event.ActionEvent evt) {

Ingresar.setEnabled(Nuevo.isSelected());

}

(For information about the "equals" method, see: http://leepoint.net/notes-java/data/expressions/22compareobjects.html)

Hope this helps.

laginimaineba at 2007-7-12 22:21:33 > top of Java-index,Java Essentials,New To Java...
# 2

> Hello all

>

> I'm having problems with a checkbox and a button. I

> want that when i click on the checkbox, the button is

> set to Enabled, and if i uncheck the button is set

> to disabled again. When the applet starts the button

> is disabled by default, and the checkbox is

> unchecked. Here is my code so maybe you guys can tell

> me what is wrong.

What [b]is[/b] wrong? From what you say, things seem to be working just fine. The button is disabled when the checkbox is unchecked. Isn't that what you wanted?

> [code]

> private void

> NuevoActionPerformed(java.awt.event.ActionEvent evt)

> {

> if(Nuevo.equals(true)){

>Ingresar.setEnabled(true);

>}

>else{

> Ingresar.setEnabled(false);

> }

>}

> de]

Why bother with that? Why not just call Ingresar.setEnabled(Nuevo)? By the way, method names and variable names should start with lower-case letters, and class names with an Uppercase one. At first glance, your code seems to do something quite different to what it probably actually does!

georgemca at 2007-7-12 22:21:33 > top of Java-index,Java Essentials,New To Java...
# 3
Yeah thats what i wanted I'm new to netbeans and there are lots of things i don't know.. that is part of an applet that does CRUD operations. Thanks people! :-D
River_Platea at 2007-7-12 22:21:33 > top of Java-index,Java Essentials,New To Java...
# 4

> Yeah thats what i wanted

>

> I'm new to netbeans and there are lots of things i

> don't know.. that is part of an applet that does

> CRUD operations.

>

>

> Thanks people! :-D

Can I give you some honest advice? Stop using NetBeans until you know what you're doing a bit better. Almost every experienced programmer will give you similar advice

georgemca at 2007-7-12 22:21:33 > top of Java-index,Java Essentials,New To Java...
# 5
George:So what IDE do you think i could use? or just use a notepad... with the console?
River_Platea at 2007-7-12 22:21:33 > top of Java-index,Java Essentials,New To Java...
# 6
you can use notepad actually to create complex swing apps. You just have to learn how to code with the javax swing library. myself, i recommend eclipse.
petes1234a at 2007-7-12 22:21:33 > top of Java-index,Java Essentials,New To Java...
# 7

> George:

>

> So what IDE do you think i could use? or just use a

> notepad... with the console?

Yep. Sooner or later you'll have to deal with that, but if all you've ever known is IDE-land, you'll be a bit out of your depth, despite actually being a good coder. Not a pleasant position to be in!

georgemca at 2007-7-12 22:21:33 > top of Java-index,Java Essentials,New To Java...