Solved

checkboxes

Posted on 1998-03-20
8
166 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
Comment Utility
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
Comment Utility
What type of object are you talking about? Canvas, component, lightweight comonent, graphics object written on a component?
0
 

Author Comment

by:suhani
Comment Utility
There are graphics object drawn on canvas.
Do you mind giving me an example of the coding.
0
 
LVL 6

Accepted Solution

by:
jpk041897 earned 30 total points
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:suhani
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ach...! Make that

public static void Sem1{
   static boolean flag;
}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert ArrayList of custom objects to JSON 4 53
IT Company 5 67
maven java path setting 5 49
ArrayIndexOutOfBoundException 9 29
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now