Solved

checkboxes

Posted on 1998-03-20
8
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

737 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