Solved

checkboxes

Posted on 1998-03-20
8
170 Views
Last Modified: 2010-04-16
I'm using checkboxes in my applet. When I clicked on a checkbox, it activated and display an object on a canvas. But when I clicked it again so that it is unticked, supposedly the object will be gone but it didn't. So, it just responded to one action.
Now how do I make it removes the object when I untick it and make it displays the object when I click it again?
0
Comment
Question by:suhani
  • 4
  • 3
8 Comments
 

Expert Comment

by:royko
ID: 1233700
u will need to code in such a way that when u perform an event to
unitck the checkbox u will remove the object and refresh the
applet.So when u tick the checkbox again , u will display the object and refresh the applet
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1233701
What type of object are you talking about? Canvas, component, lightweight comonent, graphics object written on a component?
0
 

Author Comment

by:suhani
ID: 1233702
There are graphics object drawn on canvas.
Do you mind giving me an example of the coding.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
jpk041897 earned 30 total points
ID: 1233703
The simplest approach would be to set up a semaphore. You can do this by defining a static class that contains a flag member variable (say a boolean).

If you instantiate this class in both your check box event handler and your paint() method, you could then code the paint() method to either display or not diplay the data depending on the value.

Since you did not post the code for your event handler or your paint method, and did not specify for which version of the JDK, I can only give you a rough idea:

static class Sem1{
   boolean flag;
}

//inside your event handler

...
Sem1 Semaphore = new Sem1();

// if uncheking

Semaphore.flag = false;
YourCanvas.paint();

// if checking

Semaphore.flag = true;
YourCanvas.paint();
...


// Inside your canvases paint method

...
Sem1 Semaphore = new Sem1();

if (Semaphore.flag){

// Your code do draw the data here

}
...
0
 

Author Comment

by:suhani
ID: 1233704
When I try to compile it, it gave me this error message:
 Class or interface declaration expected.
static class Sem1 {

I've never heard od a static class. Could you please explain this to me? Anyway, I'm using JDK1.1 version.

This is my event handler method:
public void itemStateChanged(ItemEvent e) {
            Sem1 Semaphore = new Sem1();

            if(e.getItemSelectable() == win3.c6) {
                  Semaphore.flag = true;
                  panel2.maps.paint();
            }
            else {
                  Semaphore.flag = false;
            }      
      }

This is my paint method:
public void paint (){
            Sem1 Semaphore = new Sem1();

            if (Semaphore.flag) {
                  g = getGraphics();
                  g.drawRect(100, 150, 40, 40);
            }
      }

0
 

Author Comment

by:suhani
ID: 1233705
When I try to compile it, it gave me this error message:
 Class or interface declaration expected.
static class Sem1 {

I've never heard od a static class. Could you please explain this to me? Anyway, I'm using JDK1.1 version.

This is my event handler method:
public void itemStateChanged(ItemEvent e) {
            Sem1 Semaphore = new Sem1();

            if(e.getItemSelectable() == win3.c6) {
                  Semaphore.flag = true;
                  panel2.maps.paint();
            }
            else {
                  Semaphore.flag = false;
            }      
      }

This is my paint method:
public void paint (){
            Sem1 Semaphore = new Sem1();

            if (Semaphore.flag) {
                  g = getGraphics();
                  g.drawRect(100, 150, 40, 40);
            }
      }

0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1233706
My appologies, I'm doing mixed coding in JAVA and C++ and got the syntax messed up.

The appropiate syntax is:

class Sem1{
       static boolean flag;
    }

Making a member of a class static makes the class static, I.e.: it insures that all instances of a class reside in the same address space, thus sharing the storage space and allowing the construction of a semaphore.

Besides this mistake on my part, your code looks prety good.
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1233707
Ach...! Make that

public static void Sem1{
   static boolean flag;
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question