HELP: disabling  the corresponding buttons

I'm on the last step of this program. Basically what i'm having trouble with is as follows:
�     When the circle gets all the way to an edge, disable the corresponding button. When it moves back in, enable the button again.
I have put in BOLD where my errors occur. It seems to be simple placement of { } brackets but everytime I place one somewhere code is interrupted in another location.
//   CirclePanel.java
//   A panel with a circle drawn in the center and buttons on the
//   bottom that move the circle.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class CirclePanel extends JPanel
    private final int CIRCLE_SIZE = 50;
    private int x,y;
    private Color c, r, o, bl, b;
    CirclePanel circlePanel;
    // Set up circle and buttons to move it.
    public CirclePanel(int width, int height)
    circlePanel = this;
     // Set coordinates so circle starts in middle
     x = (width/2)-(CIRCLE_SIZE/2);
     y = (height/2)-(CIRCLE_SIZE/2);
     c = Color.green;
     r = Color.red;
     o = Color.orange;
     bl = Color.black;
     b = Color.blue;
     // Need a border layout to get the buttons on the bottom
     this.setLayout(new BorderLayout());
     // Create buttons to move the circle
     JButton left = new JButton("Left");
     left.setMnemonic ('L');
     left.setToolTipText ("Moves the circle in the left direction 20 pixels");
     JButton right = new JButton("Right");
     right.setMnemonic ('R');
     right.setToolTipText ("Moves the circle in the right direction 20 pixels");
     JButton up = new JButton("Up");
     up.setMnemonic ('U');
     up.setToolTipText ("Moves the circle upward 20 pixels");
     JButton down = new JButton("Down");
     down.setMnemonic ('D');
     down.setToolTipText ("Moves the circle in the downward direction 20 pixels");
     // Add listeners to the buttons
     left.addActionListener(new MoveListener(-20,0));
     right.addActionListener(new MoveListener(20,0));
     up.addActionListener(new MoveListener(0,-20));
     down.addActionListener(new MoveListener(0,20));
     // Need a panel to put the buttons on or they'll be on
     // top of each other.
     JPanel buttonPanel = new JPanel();
     buttonPanel.add(left);
     buttonPanel.add(right);
     buttonPanel.add(up);
     buttonPanel.add(down);
     //Creates a button for each new color
     JButton red = new JButton("Red");
     JButton orange = new JButton("Orange");
     JButton black = new JButton("Black");
     JButton blue = new JButton("Blue");
     // Add listeners to the color buttons
     red.addActionListener(new ColorListener(r));
     orange.addActionListener(new ColorListener(o));
     black.addActionListener(new ColorListener(bl));
     blue.addActionListener(new ColorListener(b));
     //Adds the color buttons to the panel
     JPanel colorPanel = new JPanel();
     colorPanel.add(red);
     colorPanel.add(orange);
     colorPanel.add(black);
     colorPanel.add(blue);
     // Add the button panel to the bottom of the main panel
     this.add(buttonPanel, "South");
     this.add(colorPanel, "North");
    // Draw circle on CirclePanel
    public void paintComponent(Graphics page)
     super.paintComponent(page);
     page.setColor(c);
     page.fillOval(x,y,CIRCLE_SIZE,CIRCLE_SIZE);
    *// Class to listen for button clicks that move circle.*
    *private class MoveListener implements ActionListener*
    *private int dx;*
    *private int dy;*   <--- Syntax Error { Expected
   *     if (x > -60 )*
   *          left.setEnabled(true);*
*      if (x < -60)*
*          left.setEnabled(false);*  <--- Syntax Error } Expected
     // Parameters tell how to move circle at click.
     public MoveListener(int dx, int dy)
         this.dx = dx;
         this.dy = dy;
     // Change x and y coordinates and repaint.
     public void actionPerformed(ActionEvent e)
         x += dx;
         y += dy;
         repaint();
    // Listens for button clicks that change the circles color
    private class ColorListener implements ActionListener
         Color circleColor;
     // Constructor
     public ColorListener(Color buttonColor)
          circleColor = buttonColor;
     // Repaints the circle according to which button is pushed
     public void actionPerformed(ActionEvent e)
          c = circleColor;
         circlePanel.repaint();
}

I've just posted a reply in the programming forum (after you were redirected here)

Similar Messages

  • Disable the Refresh Button. Please Help.

    Folks
    I need to solve a problem.
    I have an applet that takes on data from the user and click on
    the submit button.
    Now,I would like to disable the refresh button on the browser so that
    the user cannot refresh.
    Is it possible to disable the refresh button thru the applet?
    or via JavaScript?
    Please can anyone tell me how to do this??

    Hi
    I do not think it is possible to disable refreshing altogether. You might simulate something that looks the same by running the applet with 100%/100% dimension and launching that in a new browser window that has all the controls disabled, but that's not really a solution. It's more obfuscating.
    Why can't you store the values entered into the applet as a cookie? Then if the applet is refreshed init() will be called, check for cookies there and restore the state.
    Greets
    Bhun.

  • How to disable the Save button For a pdf?

    Hi,
    I have a requirement that when you open the livecycle developed pdf, the Save option available in the toolbar (Save As icon) and File menu of the Reader should be disabled. A button will be provided in the form separately to provide the Save functionality. Can anybody help me reg. this? Is there any setting available for this in Adobe Pro or any other tool?
    Regards,
    Maria

    It's not really difficult to disable the save button. But it depends on the context from where you want to delete it. even if you disable the save button the user has the option to print screen and create a fresh pdf. So your question has some philosophical aspects to deal with. Please mail me at [email protected] incase of further quries. I've understood your problem and have got a solution but it's not somewhat legitimate to do. I can share it with you through email.

  • How to disable the cancel button in the ProgressMonitor

    hi,
    I need to know, is there any way to disable/remove the (cancel)button in the ProgressMonitor?
    One more problem is,
    Once i click the cancel button, isCanceled() return true, how to make it false again so that the process continue....
    It is very urgently.....
    please help me out.
    Thanks in advance.
    Regards,
    Deepa Raghuraman

    I don't think that's a good solution, because Cancel button itself is not disabled, so user is tempted to click it and nothing happens.
    A better but dangerous solution is this:
    progressMonitor = new ProgressMonitor(ProgressMonitorDemo.this,
                                         "Running a Long Task",
                                         "", 0, 100);
    progressMonitor.setMillisToDecideToPopup(0);
    progressMonitor.setMillisToPopup(0);
    progressMonitor.setProgress(0);
    JDialog dialog = (JDialog)progressMonitor.getAccessibleContext().getAccessibleParent();
    JOptionPane pane = (JOptionPane)dialog.getContentPane().getComponent(0);
    pane.setOptions(new Object[]{});Refer to the same question here [http://stackoverflow.com/questions/512151/how-do-i-disable-the-cancel-button-when-using-javax-swing-progressmonitor] .

  • Need to disable the submit button record wise

    Hello all,
    I have two blocks. Block A and Block B. Block B is a summary block which records will be displayed.
    Block A is a Control block and i have a submit button in it.
    Based on some records in block B i need to disable the submit button .I would be record wise.
    Please guide regarding the trigger use on this
    Regards,
    \Kiran

    Kiran,
    You can write the code in the WHEN-NEW-RECORD-INSTANCE trigger of the block B. it will fire when you navigate to that record.
    Hope this helps.
    Regards,
    Manu.

  • Disable the 'CHANGE' button in CRMD_ORDER

    Hi Experts,
    I have a requirement, where I need to disable the change button in CRMD_ORDER transaction for only few orders...
    am not sure about the disabling the change button, so I tried to disable the fields for input.
    I tried to use the function module 'CRM_INTLAY_SET_PROCESS_TYPE' and also other BADIs like CRM_ORDER_AUTH_CHECK, CRM_BTX_EXTENSIONS...but not able to disable the fields completely.
    The Conditions tab at the item level is still in change mode...
    Appreciate your help on this..
    Thanks
    Padma.

    Hi Padma,
    If you plan to use your idea with CRM_ORDER_AUTH_CHECK, you must also set the CRM_PRIDOC_COMM_BADI for the item condition tab. Set the CS_COMADM_I_COM-KAEND_TYP as 'X' in this BAdI.
    And implement note1148666 too, if your version is fit.
    Regards,
    Masayuki

  • Disable the 'Approve' button on the TRIP Tcode

    Hi ,
          I need to Disable  the 'Approve' button on the TRIP Tcode ( Travel management)  security setting.  User does not want TRIP tocde to be able to approve their own trip expenses. The approval button should be enabled in PR05 but not in TRIP.
    So can someone suggest me, Can we achieve this through object restriction? Or else Do we need to change the codeing with the help of ABAPer .
    Thanks & Regards
    Umashankar
    SAP Security

    Eliminate the Option from the TCode screen by using Transaction Variant and then create a Variant Transaction for that. Assign this new custom TCode to the Users.
    To know more on this process, please check the following thread just discussed:
    Variant using SHD0
    Regards,
    Dipanjan
    Edited by: Dipanjan Sanpui on Jul 7, 2009 6:59 PM

  • Disabling the Close Button of JFrame or Frame

    Dear Friends,
    can anybody please help out to solve the problem i am having in disabling the close button of Jframe . Or try for hiding the close button from the screen
    thanks kalyan

    to disable the close button
    myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE)

  • How to disable the submit button

    Hello ,
    I have multiple controls on a page . I want to disable submit button until the user enters all the fields .
    How to do this . appreciate your help in this .
    rgds
    kumar

    Hi Kumar,
    watch this post: disabling the submit button
    Tobias
    http://apex-at-work.blogspot.com

  • How To: Disable the Print button until Required Fields are filled out

    I have a PDF Form that I have created using LiveCycle Designer 8. On my PDF Form, I have a bunch of fields that are required. Is it possible to disable the Printer button until the user fills out all the required fields? We don't want a user being able to print out an incompleted form.

    It's not possible.
    However, you can create buttons on your document that "help" the user print
    just a part of the document: a certain page range, just the current page,
    etc.

  • How to disable the "Navigator" button on Nokia 621...

    Hi,
    Anybody knows if there is a way to disable the "Navigator" button on Nokia 6210? 
    It gets accidentally pressed (when in pocket or when trying to answer a call etc.) and the GPS eats all the battery..

    this cant be disabled unfortunatly its a built in feature and as you said you keep accidently pressing it this happens im afraid
    If  i have helped at all a click on the white star below would be nice thanks.
    Now using the Lumia 1520

  • How to disable the AET button on Web UI?

    Hi all,
    Does anyone know how to disable the AET button in the Web UI? Our customer doesnu2019t want the end users to change any configuration and the only thing left for this is hide/disable the AET functionality.
    Thank you very much in advance.
    Kind regards,
    Alvaro

    Alvaro,
    The AET should not be visible to end users, especially not in the production system.
    This should be done by authorisation.
    If you are referring to the personalization, you can disable this in the businessrole by selecting a value for the parameter PERSONALIZATION.
    If there are no values available, you can maintain them in sm30 --> PERSCV_PROFILE.
    Hope this helps.
    Regards,
    Pieter Rijlaarsdam

  • Is it possible to disable the PREV button?

    I need to prevent people from navigating back to the previous page. Is it possible to disable the PREV button?

    It is clear now that choices made are remembered - even when you navigate back and follow another path - until the form is submitted. Indeed, the response table only shows the valid choices. I can see a number of reasons why this was implemented in the way it is because it is less frustrating for a user has completed the responses on a page, but is navigating back and then returns on that page with all the choices made remembered. However, as a forms creator you need to be aware of this and add aditional rules to prevent double or wrong actions as a result of "just remembered" choices. And that is what I did to solve the problem, I added additional rules.
    Thanks for the help!

  • How can I disable the previous button in the first page and the next button in the last page?

    Hi all,
    I have created a new skin for a webhelp by modifying the layout and the buttons. However, I am not able to find a way where in we can
    disable the previous button ini the first page of the webhelp and hte the next page in the last page of the webhelp. If both the next and previous button is visibile in the first and last page, it is sort of misguiding the user.
    I am using Robohelp 9.
    Please advice.
    Thanks,
    Parag

    I think you are mixing Previous and Next in a browse sequence and the Previous and Next that you get in the browser itself.
    In a browse sequence, they are automatically disabled at the start and finish. When in the first topic in the sequence only Next will be enabled, when in the last topic only previous will be enabled.
    Previous and Next in the browser are working on the topics your user has viewed which is not the same thing.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • How can I disable the Voicemail button on an iPhone 4

    How can I disable the Voicemail button on an iPhone 4 or
    if that is not possible can i programme it to dial my own phone rather than my carrier's Voicemail box?

    No, it's not possible to disable that button and no, it's not possible to reprogram it to anything else.

Maybe you are looking for

  • How to delete parent and child records?

    Hi friends, I have a Master table and a child table. The Child table got reference key with the master table without on delete cascade. Now, I want to delete the Master records and also it's corresponding child records. How to do? Thanks in adv, rega

  • Search not working in music library with newest update

    since the iTunes update, I cannot type anything in the search box when looking in my music library.  Anyone have this issue? any cures??

  • Server, Multiple JVMs sources

    Hi, i've to create a (web serivce) server application. This application should be ready for clustering or something, if one server isn't fast enough. I know already some things abou concurrency in Java. I'm no Java newbie. But i don't know how cluste

  • Is it possible to extend jdeveloper in this way?

    I'm wondering if its possible to extend jdeveloper's source editor, in jdeveloper. For instance if I have a custom file I want to have syntax highlighting (with my own syntax) and I want to add another tab to the file for a different view of the file

  • Airport Utility 6.0 and AppleTV :)

    The new airport utility 6.0 shows my Apple TV2 as Apple-TV-3 Jerry