Results 1 to 4 of 4
  1. #1
    pheonix is offline Member
    Join Date
    Apr 2008
    Posts
    42
    Rep Power
    0

    Default problem with a guarded block !

    i've created a button in netbeans and it calls a method that involves a file IO, o when i want to modify the code inside buttonMouseClicked i can't because it says its guarded !!
    private void jButton41MouseClicked(java.awt.event.MouseEvent evt) {
    getDefinition(); <==== CAN'T DELETE THIS!
    }

    how can i solve this please ?
    thanks in advance :D

  2. #2
    pheonix is offline Member
    Join Date
    Apr 2008
    Posts
    42
    Rep Power
    0

    Default

    Guys please ive been waiting for ur reply since tuesday :'( .. I really need help in this .

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    This is not truly a Java question but instead is a NetBeans-related question. If you continue without a decent reply, you might want to look for a NetBeans forum. Myself, I avoid using NetBeans generated code but instead code all my Swing apps by hand. Best of luck.

  4. #4
    mityay is offline Member
    Join Date
    Jun 2009
    Posts
    8
    Rep Power
    0

    Default guarded block issue -- please help

    I have attempted to implement an example of guarded blocks I've obtained at Guarded Blocks (The Java™ Tutorials > Essential Classes > Concurrency) The following code was generated:

    Main.java:

    package testthreads3;

    public class Main extends Thread
    {
    public static void main(String[] args)
    {
    Boolean joy = false;
    Thread1 thread1 = new Thread1(joy);
    Thread2 thread2 = new Thread2(joy);
    thread1.start();
    thread2.start();
    }
    }

    Thread1.java:

    package testthreads3;

    public class Thread1 extends Thread
    {
    private Boolean joy;

    public Thread1(Boolean joy)
    {
    this.joy = joy;
    }

    public synchronized void guardedJoy()
    {
    while(!joy)
    {
    try
    {
    wait();
    } catch (InterruptedException e) {e.printStackTrace();}
    }
    System.out.println("Joy and efficiency have been achieved!");
    }

    @Override
    public void run()
    {
    guardedJoy();
    }
    }

    Thread2.java:

    package testthreads3;

    public class Thread2 extends Thread
    {
    private Boolean joy;

    public Thread2(Boolean joy)
    {
    this.joy = joy;
    }

    public synchronized void notifyJoy()
    {
    joy = true;
    notifyAll();
    }

    @Override
    public void run()
    {
    notifyJoy();
    }
    }

    From my understanding, Thread1 is in waiting state and has joy set to false. Thread2 sets joy to true and sets Thread1 back to ready state with notifyall() method. On the contrary, the following occur unexpectedly:
    1) Both threads have two different instances of joy of different values. I expect the values to be the same since they both refer to the same variable joy defined in main.
    2) Thread1 is never notified. InterruptedException is never thrown and the program keeps running.

    Please help, greatly appreciate

Similar Threads

  1. need block letters??
    By dc2acgsr99 in forum New To Java
    Replies: 16
    Last Post: 01-29-2008, 09:31 AM
  2. Programming block
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 12:20 PM
  3. try...catch block
    By javaplus in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 08:53 PM
  4. Return to try block
    By Freddie in forum New To Java
    Replies: 2
    Last Post: 05-11-2007, 09:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •