Can I exit from paintComponent?  ...or... how can I check for invalid data?

I'm writing a calendar applet for a programming class and I've nearly completed it but I'm stuck at checking for valid data.
What seems to be happening is that paintComponent() is being called before actionPerformed.
In actionPerformed (when they click the button), it checks to make sure they entered a valid month (1 to 12). If the didn't it dispalys a message, but if they did it calls repaint().
But even if repaint() isn't called, Java still seems to call it before actionPerformed and I get exceptions.
So I tried checking inside of paintComponent() by using a simple if(...) return; but that doesn't seem to do anything... it just keeps going through with the method.
So -- Once the user presses my button I want to make sure the data is valid before repainting the screen. How can I do this?

I validate it in actionPerformed which is called by
the action listener... that is what you meant right?
The problem is that it seems paintComponent() is being
called before I can validate the data with
actionPerformed(). I need to stop paintComponent()
from always being calledMVC. (Model, View, Controller)
Initially the internal value of the data (the model) should be valid (or null with a check in the paintComponent method)
paintComponent (the view part) shows the state of the valid data.
You press the button.
actionPerformed is called (the controller).
It checks the value and, if valid, writes it to the data (model), then updates the view.
At no point will the view have to render invalid data, because the model is only updated after actionPerformed checks the value.
The pattern may be applied with different classes performing the three roles, or different methods in the same class (sometimes it's easier that way for simple cases).
Pete

Similar Messages

  • Hi, I am trying to download IOS7 to my ipad. The programme has locked at the 'Choose a Wif-Fi network' page, a box says 'joining other network' but the page is greyed out and can't move from it.  How can I clear this screen and finish the download. Thanks

    Hi, I am trying to download IOS7 (not sure if it's 1 or 2) to my ipad. The programme has locked at the 'Choose a Wif-Fi network' page, a box says 'joining other network' but the page is greyed out and can't move from it.  How can I clear this screen and finish the download. Thanks

    Hello Den53,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    iOS: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/HT1430?viewlocale=en_US
    Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider.
    After the device has turned off, press and hold the Sleep/Wake button until the Apple logo appears.
    Best of luck,
    Mario

  • How do I check for null date entires using custom JScript on a SharePoint NewForm.aspx?

    Hi,
    I have the below JScript:
    /*Function to convert the US Date format to UK date format */
    function parseDate(input) {
    var parts = input.split('/');
    // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]])
    return new Date(parts[2], parts[1]-1, parts[0]); // months are 0-based
    /*Function to check if end date is before the start date */
    function checkDates(){
    var sd = parseDate($("input[title='From']").val());
    var ed = parseDate($("input[title='Until']").val());
    if(sd > ed) {
    alert("Please check From and Until Date");
    $("input[value$='Save']").attr('disabled', true); //hide save button
    else
    $("input[value$='Save']").attr('disabled', false); //show save button
    The above works fine for checking sd > ed but I can't seem to check for null's, I have attempted the below which doesn't work:
    /*Function to convert the US Date format to UK date format */
    function parseDate(input) {
    var parts = input.split('/');
    // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]])
    return new Date(parts[2], parts[1]-1, parts[0]); // months are 0-based
    /*Function to check if end date is before the start date */
    function checkDates(){
    var sd = parseDate($("input[title='From']").val());
    var ed = parseDate($("input[title='Until']").val());
    if( (sd > ed) || (sd == null) || (ed == Null) ) {
    alert("Please check From and Until Date");
    $("input[value$='Save']").attr('disabled', true); //hide save button
    else
    $("input[value$='Save']").attr('disabled', false); //show save button
    Any help appreciated.

    Hi aspnet-scotland,
    Please post ASP.NET related questions in
    ASP.NET forums where you could receive better responses.
    Thanks for your understanding.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Can't Check For Invalid Date

    Why does the following code not detect that the date (i.e. the month) is invalid?
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date;
    public class dateCompare
         public static void main(String[] args)
              String startDateString = "15/22/2002";
              try
                   SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                   sdf.parse(startDateString);
              catch (ParseException e)
                   e.printStackTrace();
    }

    I modified your code like this:
    Date date = sdf.parse(startDateString);
    System.out.println(date);And this is the output it produced:
    Sat Mar 22 00:00:00 PST 2003
    So, it looks like it's taking the 15, assuming you mean 12 + 3 months, and applying that to the year --- thus, it becomes March 2003.

  • ▌(ver 29) Can't exit from settings!

    Win7
    Australis
    ● Problem:
    I can open "Customize" menu <[ + ]> , but can't exit from it!
    ● Description:
    when I'm in this Drag&Drop menu, "Edit Customize"button <[ + ]> is clickable, but doesn't work and "Menu" button <[ ≡ ]> even can't be selected !!! Only restart... (Private Mode too)
    ● My story
    The begining is ordinary: installation, happiness, tutorial, customization, Problem
    Ok, let's solve. Google doesn't answer, Mozilla somewhere advices to reset FFox settings.
    Ok, the theme and addons are deleted (one of them I'll never find again*), but the problem is fixed!
    Ok, I'm happy. Let's continue. Oh, the TUTORIAL again, nice.
    STOP! "<[ ≡ ]> → <[ + ]>" ... It's here AGAIN ! I CAN'T EXIT CUSTOMIZE MENU . After tutorial. NOT OK
    ● So, I hope I've described you everything I could
    Thank you for Australis, it's a really big step
    Good luck
    ═════════════════════════════
    *FFox had a button (red cross) "restore closed tabs". I enjoyed it, but reset has deleted it and I can't find it in the addon store. I have been always thinking it is the default feature... Can you explain this too?

    Thanks!
    SOLVED (addon)
    It worked in the Safe Mode
    So, I started experiments and found that there were no proplems after I had turned of "E-Web Print 1.19.00" (by Epson)
    I think that it caused this problem. I don't use it too often, so it's better for me to turn it off. But I can't understand how does Firefox let this app make a such trouble

  • I have recently updated my CC programs to the latest version and now all of my files wont open by default into their respective programs, only if I open the program and go to file open and open the file from there. How can I fix this?

    I have recently updated my CC programs to the latest version (CC2014) and now all of my files wont open by default into their respective programs, only if I open the program and go to file>open and open the file from there. How can I fix this?
    I have tried 'Open with' and the version of the program now installed on my computer isn't even suggested as an option and when I browse for it, the file wont open with it anyway

    On Windows (don't know about Mac), the latest version will always take over the file association, and become the default for indd files. It's impossible to change it.
    But there is a plugin for ID that makes this possible. Never tried it myself.
    https://www.rorohiko.com/wordpress/downloads/lightning-brain-soxy/

  • All the CD's I have imported will not play. The only music that will play is cd's I have purchased from itunes. How can I get all my albums to play, please??

    All the CD's I have imported will not play. The only music that will play is cd's I have purchased from itunes. How can I get all my albums to play, please??

    iTunes Store- Transferring purchases from iOS device or iPod to a computer
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    How to dowload purchased music

  • If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?

    If I imported a CD into my iTunes library from one computer how can I listen to it from another computer?  I imported music from a CD into my compter at work and when I got home and went to my iTunes account none of the songs were in my library.  I also noticed that on my Work computer there were a couple songs that I had to click on the little 'cloud' icon before I could listen to them (these were not songs I imported they were songs that were already in my library).  Not sure if this makes semse...help.

    jamie171 wrote:
    My question is since I have imported them into my iTunes library from one computer why can't I access them from my iTunes library from another computer that I have authorized to access whats in my library?  Is there no way to import songs only once into the library and then access them from all my authorized computers?
    Only if you have iTunes Match or of the computers are on the same local network.

  • So I bought an iphone 4 from ebay and when I got it it was already signed into an icloud account. When I contacted the seller he said he would try to get the password but i haven't heard from him. How can I sign out of her icloud w/out the password

    So I bought an iphone 4 from ebay and when I got it it was already signed into an icloud account. When I contacted the seller he said he would try to get the password but i haven't heard from him. How can I sign out of her icloud w/out having to have the last users password

    Bmscotr5 wrote:
    How can I sign out of her icloud w/out having to have the last users password
    You cannot.
    Removing a device from a previous owner’s account
    Try and get a Refund.

  • Wanted to put a file via a drag and drop into applications on my finder sidebar.  it missed and landed in the sidebar itself.  i can not remove it.  i can not even highlight it.  how can i remove it from the sidebar.

    I wanted to put a file via a drag and drop into applications on my finder sidebar.  it missed and landed in the sidebar itself.  i can not remove it.  i can not even highlight it.  how can i remove it from the sidebar.

    Try holding down the Command key and dragging the file well off the sidebar.
    Hope this helps.

  • I have apps from old work account that I can't remember the password to. On my personal phone those apps keep showing up but I can't update them because I can't remember the password. How can I delete them and download on my new account?

    I have apps from old work account that I can't remember the password to. On my personal phone those apps keep showing up but I can't update them because I can't remember the password. How can I delete them and download on my new account?

    Tap and hold an app until they all start jiggling and an X appears in the icon's top left corner. One by one tap the X to delete the app. when they are all gone you are free to buy them again with your own account.

  • HT204152 I am unable to update my App  store Updations. the reason being billing problem asking to update payment method.many times i updated my credit card details but refusing from the system .how can i update my app store updations like  Face book etc.

    I am unable to update my App  store Updations. the reason being billing problem asking to update payment method.Many a  times i updated my credit card details but refusing from the system .how can i update my app store updations like  Face book etc....Using ! phone 6plus  .IOS8.3

    What do you mean by 'refusing from the system', if you are getting an error message then what does it say ?
    For a credit card to have a chance of being accepted it needs to be registered to the same name and address (including format and spacing etc) that you have on your iTunes account, and have been issued by a bank in the country where you and your iTunes account are. If it is and if you are getting a 'declined' message then you could check with the card issuer to see if it's them that are declining it, and if not then try contacting iTunes Support (these are user-to-user forums) and see if they know why it's being declined : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If when trying to download you are getting a message about a 'problem with a previous purchase' then that implies that iTunes wasn't able to collect the money for your last purchase. If that is the case then you won't be able to download anything else (including app updates) until you've paid off what you owe : Pay an unpaid balance in the iTunes Store - Apple Support
    If you aren't getting the 'problem with a previous purchase' message then try logging into your account (not when trying to download something) and see if you get the 'none' option so that you can remove the card's details and be able to download updates to your apps : Change or remove your payment information from your iTunes Store account (Apple ID) - Apple Support

  • HT201274 I have my brothers icloud account on my ipad and i want my icloud account back I have all my games from my acount but I can see his massages notes etc how can I get my icloud account back I tried so many things please help .???

    I have my brothers icloud account on my ipad and i want my icloud account back I have all my games from my acount but I can see his massages notes etc how can I get my icloud account back I tried so many things please help .???

    go to settings and sign out his apple id in the sections i tell you:
    1.game center
    2.itunes and appstore
    3.messages
    4.icloud(delete acount;it wont realy delete it will only remove from your ipad)
    5.facetime
    and then enter your icloud in each and every section

  • I have just updated my phone in icloud and I have lost all my data including my large music collection from itunes. How can I recover my music and phone list?

    I have just updated my phone in icloud and I have lost all my data including my large music collection from itunes. How can I recover my music and phone list?

    Welcome to the Apple Community.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option which is revealed in the iTunes app on your iOS device by tapping the more button at the bottom of the screen.

  • HT4059 i purchased a tour guide book and would like to view and print from my PC, how can I?

    i purchased a tour guide book and would like to view and print from my PC, how can I?

    You purchased an ibook?
    Can I print my books and PDFs from iBooks?
    Yes, you can print PDFs and notes you've entered from iBooks, but the option to print ePub books is not available.2You can also email PDFs and notes you have written from iBooks."
    iBooks: Frequently Asked Questions (FAQ)

Maybe you are looking for

  • If I change a file name, how can I get all the links to update?

    I've recently finished my webpage (kensingtonconcertseries.com),.....then my client wanted to change the name of one of his pages from 'Marold Duo' to 'Rodewald-Morebello Duo.' All of my links to that page are to the original page(MaroldDuo.html). Ar

  • Where can I find an ipod nano 6th generation

    I would like to know where can I get the ipod nano 6th generation?, I live in Toulouse, France

  • Active directory Webservice error

    I have installed and configured the active directory authentication webservice. I get the following error when I try to synchronize. Does anybody know the reason for the error? Apr 28, 2006 11:35:13 AM- Sync Agent is processing memberships. Apr 28, 2

  • "Complete Album" - downloaded wrong track

    I purchased some tracks off an album a couple of months ago. Returned to iTunes store today to purchase the remaining tracks.  As expected, in iTunes store, it showed "complete album" with the price.  It also showed the tracks I needed available for

  • How can I hook a GPS to my Mac?

    I want to hook a GPS engine to my Mac Pro.  What hardware and software will I need?