Solved

checkboxes

Posted on 1998-03-20
8
168 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

809 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