Conditional "updates" to a method...?

Well, I am just learning Java... My goal is to learn enough java to convert server of the pattern (in fact dtksh) scripts. My first experience is an example of code of "gui" of "head first Java - Sierra/Bates. The code of the book works fine, but in order to understand how 'classes', 'methods' and 'Listeners' work, I tried to add a Boolean logic for the button.

The code displays a simple graphical user interface that draws a filled in circle in the central region. Pressing any key causes the circle is redesigned with new colors (random). The second button changes the label text in the Western region. What I want to do is to update the label in the Western region based on the value of the variable 'msg '.

Because I don't really understand the components, I don't know which code to include, why I included it all the!

I commented parts I added do not have ' work. In fact, mine works... but not as I want.

Goal: If 'msg' = 'true', and then change the text of the label of 'REAL' value 'false '.
If 'msg' = 'false' then change the text of the label of 'FALSE' and the value of msg to ' true
(Sofare so good... If I change my 'msg' is true or false... it works right exacltly).

What it does not change the value so the next time the button is pressed, it should be the opposite. Sense repeatidly clicking the button should change the text of Labé of ti true false and false to true.

Here's the full text... Sorry if this is too long!

Thank you

Kevin
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector.*;
public class TestGui2 {
     JFrame frame;
     JLabel label;
     boolean msg = false;  
public static void main (String[] args) {
     TestGui2 gui = new TestGui2();
     gui.go();
     }
public void go() {
     frame = new JFrame();
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     JButton labelButton = new JButton(“Change Label”);
     if (msg) {
          labelButton.addActionListener(new LabelListener()); 
          } else {
          labelButton.addActionListener2(new LabelListener2());
          }
JButton colorButton = new JButton(“Change Circle”);
     colorButton.addActionListener(new ColorListener());
     label new JLabel(“I’m a label”);
     MyDrawPanel drawPanel = new MyDrawPanel();
     frame.getContentPane().add(BorderLayout.SOUTH, colorButton);
     frame.getContentPane().add(BorderLayout.CENTER, drawPanel);
     frame.getContentPane().add(BorderLayout.EAST, labelButton);
     frame.getContentPane().add(BorderLayout.WEST, label);
     frame.setSize(500,300);
     frame.setVisible(true);
     }
class LabelListener implements ActionListener {
     public void actionPerformed(ActionEvent event) {
          label.setText(“TRUE!”);
          msg = false;
          }
     }

class LabelListener2 implements ActionListener {
     public void actionPerformed(ActionEvent event) {
          label.setText(“FALSE!”);
          msg = true;
          }
     }
class ColorListener implements ActionListerner {
     Public void actionPerformed(ActionEvent event) {
     Frame.repaint();
          }
     }
}
Published by: leonhardtk on June 30, 2011 11:22

Because it is not formatting properly, I have surround my suspicious code in asterisks.

Thank you.

Good. You have two separate listeners, but in the initialization of your treatment, you choose one of them and use it forever afterwards. The solution to this is to have only one earphone. And this listener must have a conditional logic that decides what text in the label, based on the State of the program at this time.

Tags: Java

Similar Questions

  • Hey, need help. I get this in my iPhone that 'there is a problem of billing with a previous purchase. Please update your payment method"in any way I can remove my visa card from iTunes

    Hey, need help. I get this in my iPhone that 'there is a problem of billing with a previous purchase. Please update your payment method"anyway I can remove my visa card from iTunes?

    You must pay your debt first.

  • My credit card has expired. I can't update the payment method. Now! My plan show expired. What should I do?

    My credit card has expired. I can't update the payment method. Now! My plan show expired. What should I do?

    Hello

    I don't see any subscription / membership to the title of the email that you use with the forums.

    Please share the e-mail in a private message so that we can provide you with comprehensive information.

    At the same time, if the plan has expired suggest you kindly purchase a new subscription.

    Please see: pricing and membership creative cloud plans | Adobe Creative Cloud

    I hope this information is useful!

  • Impossible to update the payment method for my creative cloud subscription

    Recently, I got my card of bank renewed, so that the file in my account is expired. I tried to update my information payment, but whenever I did it just says "billing address is invalid" or something. I discuss with 2 representatives and tried to update with TWO DIFFERENT CREDIT CARDS, even using the secure payment method. No time succeeded. I contacted the Bank, and my cards seem to work very well.

    Does anyone else have this problem?

    Hello

    I see you have a subscription to creative cloud under the same email id that you use with the forums.

    I checked the details of billing as well, I would ask you many want to use your first initial and last name by updating the details.

    This should work for you.

    Let me know if you face any issues.

  • VO join EOs 2: conditionally updating only 1 EO.

    I have a view object that joins the tables of 2 DB/EOs, mainly to display data attached in an ADF Faces table.

    However, I now apply for the user to be able to update the attached data. The user will be able to update the data that would go in one or both of the DB tables.

    Now, let's say that in a given table ADF Faces line, a user updates the data happens in A DB Table, but does not change the DB table B data. It seems that during the validation of the task flow operation runs, the framework commits data at the same time table DB A and B. This is not, I can present our application functionality - without going into details, it has to do with the UPDATE BEFORE and AFTER the UPDATE DB triggers.

    So, is there a way to configure or code so that the update only occurs when the DB Table, for which the data has actually changed? in other words, in the example above, since no data for table B has been changed, I would that the DB to update only to the Table has.

    I know that another approach is just to not use has the VO attached; However, it would be much more productive if there is a way to do it, where the question.

    Using 11g.

    Thanks for your help.

    Well, there is always a way to prevent the operation of update at the level of the entities.
    In the entity class that corresponds to table B, you can do the following:

        protected void doDML(int operation, TransactionEvent e) {
           if (operation != DML_UPDATE)
              super.doDML(operation, e);
        }
    

    Of course, you can examine the additional conditions, for example (in pseudocode):

        if ((operation == DML_UPDATE) && theUserHasReallyChangedThisEntity())
               super.doDML(DML_UPDATE, e);
        else
              super.doDML(operation, e);
    
  • Under certain conditions, update a table based on the comparison with a SQL statement

    I have a table (table 1) that has 4 columns:

    UID. THE NEST | VALUE1 | VALUE2

    I have another statement SQL (STMT) that returns the 3 columns of a few other tables:

    UID. THE NEST | VALUE1

    Now this is the condition of the way in which I want to put up-to-date TABLE1:

    First, to compare a pair of UID and PID of STMT with those in TABLE1,

    -1, for any new pair UID and PID not in TABLE1, insert a new line of STMT in TABLE1 set TABLE1. Value2 = 0 (I already did this).

    2, for an existing UID and PID pair in STMT and TABLE1, do:

    a. in TABLE1. Value2 > 0, update TABLE1. VALUE1 = STMT. VALUE1

    b. to TABLE1. Value2 = 0 and if TABLE1. VALUE1! = STMT. Value1, update of TABLE1. VALUE1 = STMT. Value1, otherwise nothing to do.

    I can't seem to come with a solution for condition 2. Any help is appreciated!

    Hello

    Here's one way:

    MERGE INTO  table1  dst
    USING          (
                 SELECT  ...   -- your stmt query goes here
             )   src
    ON         (    src.uid  = dst.uid
             AND      src.pid  = dst.pid
             )
    WHEN MATCHED THEN UPDATE
    SET           dst.value1 = CASE
                                   WHEN   dst.value2 > 0
                        OR     (   dst.value2 = 0
                             AND dst.calue1 != src.value1
                        )
                        THEN   src.value1
                               END
    WHERE   dst.value2 > 0
    OR (    dst.value2 = 0
       AND  dst.calue1 != src.value1
       )
    ;
    

    This assumes that the combination (uid, pid) is unique in stmt. It doesn't have to be unique in table1.

    sb92075 wrote:

    -1, for any new pair UID and PID not in TABLE1, insert a new line of STMT in TABLE1 set TABLE1. Value2 = 0 (I already did this).

    FUSION could also do parts 1 and 2 together, in the same statement.

    2, for an existing UID and PID pair in STMT and TABLE1, do:

    a. in TABLE1. Value2 > 0, update TABLE1. VALUE1 = STMT. VALUE1

    b. to TABLE1. Value2 = 0 and if TABLE1. VALUE1! = STMT. Value1, update of TABLE1. VALUE1 = STMT. Value1, otherwise nothing to do.

    Why are they not simply your needs ' uid and pid that already exist in stmt and table1, if table1.value2 > = 0, then the value table1.value1 = stmt.value1 "? Are you concerned about shooting triggers unnecessarily? It has something to do with null values? The MERGE statement above does exactly what you asked, but, depending on your needs, something simpler and more efficient could do it as well.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    If you ask on a DML statement, such as UPDATE, the sample data will be the content of the or the tables before the DML, and the results will be the State of the or the tables changed when it's all over.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

    Published by: Frank Kulash, June 6, 2012 14:51

  • I want to renew my teacher subscription, but I can't connect to update my payment method

    I received this message on last week:

    Your Creative cloud membership will expire on 18/09/2016. We hope that you have been getting the best out of all that creative cloud has to offer. To extend your subscription, please update the billing for your account information, or add a prepaid card.
    Update your billing information (https://accounts.adobe.com/plans//edit-payment?deeplink=true & puser =
    Thank you for being a part of the creative cloud,
    The creative team Cloud

    The problem is that I can't connect using this url, its towers indefinetly... your systems are down?

    Thanks in advance for any help you can provide

    Jim

    Hi JimTheKing,

    Please try using another browser or restart the same browser.

    If nothing helps, kindly Contact Customer Care.

    * Be sure to stay connected with your Adobe ID before accessing the link above *.

  • Join conditions, update a table

    Hello

    I created a table of choice in the apex, so my Dispatcher column, moved to the new table. (first time doing so)

    I created again the dispatcher of the column in the first table.

    I have the following code:

    SELECT R.DISPATCHER, B.DISPATCHER

    OF GCAT_V3 R JOIN GCAT_DISPATCHER_LOOKUP B

    ON R.DISPATCHER_ID = B.DISPATCHER_ID

    DISPATCHER DISPATCHER
    -SU. [email protected]
    -SU. [email protected]
    -SU. [email protected]
    -SU. [email protected]

    I need to copy the data back.

    Basically, what I have in the column that b.Dispatcher must be copied to another column dispatcher.

    Any ideas?

    Kind regards

    Leonard

    Hi, Leonard,

    Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.

    If you ask about a DML operation, such as UPDATE, then INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    You can use the UPDATE or MERGE to copy data from a table to the existing lines in another.  For example:

    UPDATE gcat_v3 r

    SET dispactcher =)

    SELECT b.dispatcher

    OF gcat_dispatcher_lookup b

    WHERE b.dispatcher_id = r.dispatcher_id

    )

    ;

    The above statement assumes that dispatcher_id is unique in gcat_dispatcher_lookup; But there is no need to be unique in gcat_v3.

  • I've updated my payment method and it will not always turn on my account

    My creative cloud account has been disabled due to payment.  I updated my payment account, it took a partial payment for the rest of the month and does not show a payment due until January 14, 2016, but it will not always turn on.

    allow a day of pst for your payment to process.

  • Method for controlling battery Microsoft acpi disables my battery on update.

    Hello


    I work with a Lenovo Y530 computer laptop (ab00216104). After a few years, the battery ceased to maintain a charge so I ordered a new third party like Lenovo temporarily stopped selling them. The new battery worked fine at first but, after a few minutes I get the message "battery plugged in, does not support" of the battery lower-left icon. It just stops charging the battery, but it will take place off the coast of the battery until it is unloaded. At first, I thought it was a bad battery however by many trial and error, I discovered the battery works fine. Let me explain.

    If I uninstall "control method battery compatible acpi Microsoft" in the Device Manager and reboot my computer with my card wireless off then the battery will work perfectly. It is not up to what I connect to the internet that it suddenly stops to load again. It is in the case once my computer is able to access to the internet and update of "control method battery compatible acpi Microsoft" that the problem occurs.

    As much, as I know there is no way to prevent it from updating once he establishes a connection and no way for "rolling back drivers" as long as this option is grayed out. I would be very happy any advice on this situation, thank you.

     

    Hello

    I suggest you to perform the following methods.

    Method 1:

    To enable or disable Windows Update driver manually on a single computer to research

    1. Click Start, right-click computer, and then click Properties.
    2. In the tasks list, click Advanced system settings.
    3. On the System Properties dialog box, click the hardware tab, and then click Windows Update driver settings.
    4. Select never check for drivers when I connect a device.
    5. Click OK twice, and then close the System dialog box.

    Method 2: install the latest drivers for chipset for laptop and the Coachman.

    If the problem persists, contact Lenovo support for assistance.

    Hope this helps!

  • waitForUpdates method does not detect updates after reset of the connection

    Hello

    In my case, I use waitForUpdates() method to detect the VMotions (. i.e. whenever a VMotion arrived I have trying the GET the update using this method). It works perfectly in case of normal use.

    But all of a sudden after a reset of VC connection. This waitForUpdates() method makes me not updated.

    When the session id gets modified waitForUpdates (propertyCollector, version) would also have a new propertyCollector object (to give you the new collector of property obtained with the new connection object), so even now why it does not return me the updates after the reset of the connection.

    Please let me know if I'm doing something wrong in the treatment of this.

    Please let me know how to handle the connection reset and collect updates later.  Which can affect the waitForupdates in updates outside the collector property object to return.

    I even tried with the checkForUpdates method was the same behavior.

    Thanks in advance.

    Please check if you create the PropertyFilter after reset connection. Good initialization of the filter property should solve your problem.

    Thank you

    Aditya

  • Windows 7 - updates at shutdown never download.

    When I turned off the computer, Windows says to install the updates. "Do not stop your computer...". "So I expect. Never install the updates.

    I turned off my firewall, BitDefender and I left the Sandboxie 'sandbox '.

    What Miss me?

    Hi Julieann75,

    This problem occurs when one of the following conditions is true:

    (a) an error has occurred during installation. The update has not been installed.

    (b) the update has been installed. However, a file was not updated to restart the computer.

    Method 1:

    You try to run the update to Windows 7 troubleshooting and check if it helps.

    Check out the link:

    http://Windows.Microsoft.com/en-us/Windows7/open-the-Windows-Update-Troubleshooter

    Method 2:

    Step 1:

    You can also view the history of update for updates failed which is causing the problem.

    Check out the link:

    See the Windows updates are installed

    http://Windows.Microsoft.com/en-us/Windows7/see-which-Windows-updates-are-installed

    Step 2:

    You try to install the updates one manually download from the Microsoft Download Center and check if it helps.

    Check out the link:

    http://www.Microsoft.com/downloads/en/default.aspx

    Hope this information is useful.

    Jeremy K
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • Cannot install updates (including the highest priority) but can install others.help.

    I use the updated mirosoft site all the time but in the last 4 or 5 days, since I had to do a reinstall of win xp, I go through the update process, which can take ages, only to be told that some updates have failed. I need help fast or the computer goes out the window.

    Method 1: reset the Windows Update components.

    http://go.Microsoft.com/?linkid=9665683>

    This tool automates the most common fixes problems with the Windows Update site.

    Note this fix it Solution has two modes by default and aggressive.

    You must run the fix it solution in default mode and determine if it solves your problem with Windows Update before running it in aggressive mode.

    The historical section Update http://windowsupdate.microsoft.com> will be white/empty after you run the Fix It in AGGRESSIVE mode.

    This will not effect either by using the Windows Update Web site or via automatic updates update.

    Method 2: check the condition of Windows Installer and installer of Modules of Windows.

    I. click on start and type Services.msc and press ENTER.

    II. Locate the Windows Installer Service.

    III. double click it to check if the service is started or not.

    IV. change the type of startup to automatic and Start the service.

    V. check the same thing for Windows Installer of Module service.

    VI. Press ok and close the Services window.

    VII. Reboot

    UTC/GMT is 18:34 Friday, May 11, 2012

  • My Windows updates do not show in the control panel

    When I click on "View installed updates" under tasks in the left side panel, I get a blank window with "no update is installed on this computer". I'm sure that I installed each updates available for my operating system, and this can be verified when I search for news updates and click "update history", that is Windows Vista Home Premium, 64-bit. This occurs even if when I check my information system (my computer > properties) it SAIS "Windows Vista Service Pack 2. Another question which maybe related to this problem is that during these 3-4 days I been received 2-updates on several occasions; KB2676562 and KB2679255.

    I appreciate any help on this issue.

    Hello

    "View installed updates" issue:

    Method 1: See the following article:

    Important: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    Steps that might help to fix Windows Update errors and a Windows features dialog box is empty in Windows Vista:

    Method 2: You can run scanning of the file system [SFC] checker on the computer that will replace missing or corrupt files & check if the problem persists.

    For more information, you can consult the following link.

    How to use the System File Checker tool to fix the system files missing or corrupted on Windows Vista or Windows 7

    Receivers 2-updates to update several times to issue:

    See the following article:

    Note: The data files that are infected must be cleaned only by removing the file completely, which means that there is a risk of data loss.

    Windows Update or Microsoft Update repeatedly offers the same update:

    Thank you all for helping me with my problem with the updates of Windows Vista.

    Finally, I was able to solve the problem by searching for a backup copy of my registry and by replacing corrupted registry by the backup.

    I highly recommend to make registry backups, when it is in good working condition.

    Thank you all again

    AJ

  • custom kb2691905 update installed

    I try to install this update but is not possible, I use also the problem of microsoft.

    Try these steps and check if you are able to install Windows updates.

    Method 1: reset the Windows Update components.

    http://go.Microsoft.com/?linkid=9665683>

    This tool automates the most common fixes problems with the Windows Update site. Note this fix it Solution has two modes by default and aggressive. You must run the fix it solution in default mode and determine if it solves your problem with Windows Update before running it in aggressive mode.

    Method 2: check the condition of Windows Installer and installer of Modules of Windows.

    I. click on start and type Services.msc and press ENTER.

    II. Locate the Windows Installer Service.

    III. double click it to check if the service is started or not.

    IV. change the type of startup to automatic and Start the service.

    V. check the same thing for Windows Installer of Module service.

    VI. Press ok and close the Services window.

    UTC/GMT is 02:13 on Friday, may 4, 2012

Maybe you are looking for