Getting Correct and Incorrect to show on my GUI

What am i missing to allow correct and incorrect to show on my GUI.
package anaquiz;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class AnAQuiz extends JPanel {
    private JComboBox choice;
    private JLabel label;
    private JTextField text;
    Button CheckAnswer;
    Button TryAgain;
    private String Answer1 = "Wilson";
    private String Answer2 = "Ace";
    private String Answer3 = "Yes";
    private String input = " ";
    boolean Answer = false;
    JLabel testresult;
    public AnAQuiz() {
        choice = new JComboBox();
        label = new JLabel();
        label.setBackground(Color.blue);
        choice.addItem("Tennis Question #1");
        choice.addItem("Tennis Question #2");
        choice.addItem("Tennis Question #3");
        text = new JTextField(42); //step 4
        Listener listen = new Listener();
        choice.addActionListener(listen);
        add(choice);
        add(label);
        add(text);
    private class Listener implements ActionListener {
        public void actionPerformed(ActionEvent event ) {
        int c = choice.getSelectedIndex();
            switch (c) {
            case 0:
                label.setText("Whats the famous tennis brand that begins with 'W'?");
                if (input.equals(Answer1))testresult = new JLabel("Correct!"); //Having difficulty getting the correct and the incorrect to show as a label
                 else testresult = new JLabel("Incorrect!");
                 break;
             case 1:
                label.setText("What do you call when someone misses a serve?");
                break;
             case 2:
                label.setText("Should you shake hands after a match?");
                break;
    public static void main(String[] args)
        JFrame frame = new JFrame("Quiz");
         frame.getContentPane().add(new AnAQuiz());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.show();

Basically adding in the code tjacobs01 demo'd for you and a little extra.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class AnAQuiz extends JPanel {
    private int chosen;
    private JComboBox choice;
    private JLabel label;
    private JTextField text;
    Button CheckAnswer;
    Button TryAgain;
    private String Answer1 = "Wilson";
    private String Answer2 = "Ace";
    private String Answer3 = "Yes";
    private String input = " ";
    boolean Answer = false;
    JLabel testresult = new JLabel("");
    public AnAQuiz() {
        choice = new JComboBox();
        label = new JLabel();
        label.setBackground(Color.blue);
        choice.addItem("Tennis Question #1");
        choice.addItem("Tennis Question #2");
        choice.addItem("Tennis Question #3");
        text = new JTextField(42); //step 4
        Listener listen = new Listener();
        choice.addActionListener(listen);
        setLayout(new BoxLayout(this, 0));
        add(choice);
        add(label);
        add(text);
          text.addKeyListener(new KeyAdapter() {
          public void keyPressed(KeyEvent ke) {
            if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
              input = text.getText();
              if ( chosen == 0  &&  input.equals(Answer1) )
                label.setText("Correct");
              else if ( chosen == 1  &&  input.equals(Answer2) )
                label.setText("Correct");
              else if ( chosen == 2  &&  input.equals(Answer3) )
                label.setText("Correct");
              else
                label.setText("Incorrect");
        add(testresult);
        testresult.setVisible(false);
    private class Listener implements ActionListener {
        public void actionPerformed(ActionEvent event ) {
        chosen = choice.getSelectedIndex();
        testresult.setVisible(true);
            switch (chosen) {
            case 0:
                label.setText("Whats the famous tennis brand that begins with 'W'?");
                break;
             case 1:
                label.setText("What do you call when someone misses a serve?");
                break;
             case 2:
                label.setText("Should you shake hands after a match?");
                break;
             default:
                break;
            text.requestFocus();
    public static void main(String[] args)
        JFrame frame = new JFrame("Quiz");
        frame.getContentPane().add(new AnAQuiz());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
}

Similar Messages

  • How do I get facebook and twitter to show up in the new notifications?

    I am trying to get facebook and twitter to show up in the notifications if I swipe left.

    You should also ask this in the MacBook Air forum. This is the forum for the white and black plastic MacBooks that were discontinued in 2010. You should also post this question there to increase your chances of getting an answer.
    https://discussions.apple.com/community/notebooks/macbook_air
    Also if you're running Mountain Lion. There's a Mountain Lion Support Community. You should also post this question there to increase your chances of getting an answer.
    https://discussions.apple.com/community/mac_os/os_x_mountain_lion

  • Get date AND time to show in the menu bar

    What is that technique to get date AND time to show in the menu bar please?

    Install iStat Menu
    System Preferences -> iStat Menus -> Date & Time
    \[X] Show Date & Time
    Format .... \[Edit]
    (*) Custom (drag tokens to build a custom format)
    Drag a light blue token into the edit line below the token selections. If you want a space a colon a dash, etc... just type that character(s) before after draging a token into place.
    I created: 9:35 PM Sat 1-Aug-2009
    You can create anything you like in any order you like.
    The other alternative (if you happen to be a fan of the Unix strftime() function) would be to use the % formatting characters in the Expert time format expression box. Use the Terminal "man strftime" to find out all the available % formatting codes.
    But I think the Custom Drag & Drop section is the easiest to use.
    However, if this doesn't work for you, then I guess it is just a case of "Your Mileage May Vary".

  • I have a Seagate Slim Portable 500 GB USB 3.0 external hard drive that worked great with my Macbook Pro 13" Retina but gets ejected and won't show files on any iMac.

    I have a Seagate Slim Portable 500 GB USB 3.0 external hard drive that worked great with my Macbook Pro 13" Retina but gets ejected and won't show files on any iMac. My Macbook Pro and the two different iMacs I tried it on were all using Mountain Lion, so the only difference was the iMac versus Macbook Pro.

    I just tried this, no luck...
    I connected a different USB cable, still the same problem. Tried both cables with the problematic hard drive on two different computers, still the same problem.
    At this point I assume I'll probably need professional help in saving the files, thanks for the assistance.

  • I have purchased Line Sticker App, iTunes already took money from credit card $2.49 AUD. But I didn't get any and also nothing show on my Line purchased box.

    I have purchased Line Sticker App, iTunes already took money from credit card $2.49 AUD. But I didn't get any and also nothing show on my Line purchased box.

    If you've been charged for the item but not received it then try the 'report a problem' page to contact iTunes Support : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes Support via this page : 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

  • How to segragate correct and incorrect records in a msg

    Hi All,
    I am working on a file-XI(BPM)-Oracle scenario.
    My input file has a field 'Applicant No', which is mandatory in the Oracle table.
    In my BPM, I have a transformation generating two message types, one for the corect msg and the other for the error.
    Next what i am doing it by means of 'Fork Step' in BPM i am segragating these msgs and sending the correct ones to the Oracle table and the erroneous ones to a file in the sender system.
    At runtime my input file contains two records, one correct and the other incorrect.
    But both the records are getting sent two both the receivers i.e in sender an error file is getting created with both the records and both the records are also trying to get inserted into the database.
    How can i overcome this problem? Is there any step in BPM which can actuaaly seperate out the two records?
    Pls guide
    Thanks in advance
    Regards
    Neetu

    Hi,
    Please use Switch and define your condition in the swtich based on which you want the data to flow to either file or JDBC.
    From SAP Help:
    You use a fork () when you want to continue a process in branches that are independent of each other, for example, to communicate with two systems that are independent of each other. The branches of the fork join in a union operator.
    You use a switch () to define different processing branches for a process. The Otherwise processing branch is created automatically.
    You define a condition for each processing branch (see also: Condition Editor). The condition is checked at runtime. The process is continued in the branch that is first to return the value true. If no branch returns the value true, then the process is continued in the Otherwise branch.
    Regards
    Vijaya

  • How do I track number of correct and incorrect mouse clicks in Hotspot quiz?

    Hi All,
    I need to create a quiz that allows me to know how many correct answers the user has clicked (there will be 20ish) and how many clicks were incorrect. Is there anyway of doing this?
    Many Thanks
    Chris M

    Hi,
    Thanks, I am currently running version 4 of captivate. The intention is that all 20 hotspots will appear in the same slide.
    So you can get an idea of the project, it will train users how to proof documents. A document shows on screen users would then click on every error they can spot. For every hotspot not in the correct area (IE over a spelling mistake) gets marked as a different variable (IE You were wrong X times).
    Thanks
    Chris M

  • In Pages, How can I get headers and footers to show up on more than the first page of each section?

    In Mountain Lion, I considered myself a fairly expert user of Pages. Since "upgrading" to Mavericks, I can't get even basic things to work anymore. My current problem is that the headers and footers are only showing up on the first page of each section. A related annoyance is that if I copy the information in a header or footer, all the associated formatting disappears when I paste it. But the first problem is the one that matters — headers and footers that only show up on one page sort of negate the whole point of headers and footers.

    If you click the link I posted previously, it takes you right to the Pages community.
    Here >  Pages: iWork: Apple Support Communities
    Then click New.

  • Getting Date and Time to Show in the Menu Bar

    I have the OS setup to set the date and time automatically and the clock set to "show date and time in the Menu Bar. I have the international set up for the Day of Week, Month, Date and Year, but the menu bar only shows "Fri X:XX:XX PM" is there any way to get it to show me Fri May XX, 2008 X:XX:XX PM"?
    Thanks for any help.
    John

    I use iClock too. It is much more customizable than the Time & Date clock provided with the system. I have used it for several years and it has been very stable for a third-party application.
    Although I have only used it for a couple of months, I also really like another third-party application you may like, to put weather conditions on the menubar called WeatherDock (freeware). It accesses Weather.com to provide the current temperature (of course) but it can include several other weather conditions (depending on how much space you have on your menubar). In addition to temperature, I have it show the weather condition (currently partly cloudy, typical in Houston), wind direction and speed (I ride a bike to the office and this tells me if I’ll be fighting it or aided), and humidity (also a Houston favorite). It will also speak the weather conditions when they change.

  • Can't get master and subpages to show in PDF doc

    I have created a PDF doc and revised it in Adobe LiveCycle.
    I can see the pages in LiveCycle, but when I PDF the doc it just shows one page.
    Please advise.

    Moved to LiveCycle Designer.
    Molly,
    People in the Designer forum have more experience with Designer related issues. I have moved it to that forum.
    Mike

  • Office Web Apps - How do I get Excel and PowerPoint to show up as options for New Documents?

    When I highlight a list of documents, a ribbon shows up at the top.  The left most action is "New Document".  Despite running and installing Excel and PowerPoint services, the only option that shows up is Word.  How do I add Excel and PowerPoint to that list?
    I have confirmed that I am able to upload, view and edit Excel and PowerPoint.  I just cannot find a way to add them as options in New Document.

    Create Content Types, same as in 2007.
    In a nutshell... Create a content type based on Document and add a PowerPoint template. Go to the library and enable Content Types in Advanced. Add the new content type to the library's list of content types. The New button will now contain the name of this new content type.
    Repeat for Excel.
    More info:
    http://msdn.microsoft.com/en-us/library/ms472236(office.14).aspxMike Smith
    TechTrainingNotes.blogspot.com

  • When I open an html file saved in UTF-8 format the 3-byte file header (usually hex EF BB BF) is shown as text at top-left. How can I avoid this - all other browsers interpret the header correctly and don't show it.

    I write VB apps that create web pages for international sports scoring systems, and these must be able to show Latin, Cyrillic, eastern names etc. that require 2-bytes for some characters in the text. This means saving in UTF-8 to avoid 8-bit ASCII files being created. UTF-8 files typically have a 3-byte header = hex EB BB BF, and with all browsers except Firefox this header is interpreted and not shown. Firefox however always displays these characters as  at the top-left screen position. What do I have to do the make Firefox recognize UTF-8 files, or do to my UTF-8 files to work properly with Firefox?
    See http://www.iacusn.org/USN2010/results/ for a typical recent example.

    You see that UTF-8 BOM (Byte Order Mark) because of the content type specification in the page code.
    <pre><nowiki>content="text/html; charset=windows-1252"</nowiki></pre>
    If you remove that or change it to utf-8 then Firefox won't show that BOM as text. There is however no need to insert that BOM at the start of the file. You can also configure the server to send the file (all files) as utf-8.

  • HT1766 what do i do because my  iphones not getting started and it is showing me itunes `s swymbol and usb `s port

    hi guys... iam stuck in a problem what can i do because my iphone is not gettin started after the restoration process and its showing me a itunes symbol and a usb port

    can anyone help me

  • Count correct and incorrect answers

    I have attached part of my code that is currently working.
    The only thing I would like to change is I would like to add
    another var counter which keeps track of wrong answer (wrong answer
    being when a user does not drop the object on the correct
    location). thanks for your time,

    initialize an incorrectCounter next to your counter and
    increment it in the else-branch of your onRelease
    if-statement.

  • Places and Faces not showing up on iPhone 4

    I've tried everything to get places and faces to show up and i cannot figure it out.
    My boyfriend has a 3GS with iLife '08 and he has faces and places.
    How do I get mine to show up?

    Have you used iPhoto to tag your photos with Face and Place information?
    The Photos app on the iPhone will only recognize Face and Place information that you've tagged photos with in iPhoto.
    Matt
    Message was edited by: Matthew Morgan

Maybe you are looking for

  • HP C309a - Blue screen - C2FE0100 Error code- 7 blinking lights!

    HP 309a - Photosmart - Up-to-date drivers, New ink too. Cleaned print head with alcohol wipes. Will not print. Control panel screen displays HP logo for about 7 seconds, then the display turns blue with white letters/numbers : C2FE0100, then same pan

  • Connecting mini-display monitor

    I have a new macbook pro and thunderbolt display...how do I connect the mini-display port display to the thunderbolt display

  • A,B,C Weighting Filter vi

    How can I make an A,B,C Weighting Filter vi for my Sound Pressure Level Meter project....??? IF there is one already made please send it to me.......[email protected] Thanks.....

  • How to add System variable in a Query

    Hi Experts, In ref. to the below query. (SELECT T0.[CardCode], T0.[CardName], T0.[DocNum],T0.[Installmnt], T0.[DocDate], T0.[DiscPrcnt], T0.[DiscSum], T0.[DocTotal] FROM [dbo].[OINV]  T0 WHERE T0.[CardName] = [%0] ) Can you please let me know how to

  • Run report in background

    I have a report that run in background.Now my aim is to save the data in excel on my desktop. Please guide me how to do so.I have used this function module SAP_CONVERT_TO_XLS_FORMAT and many more but still i'm not able to save data in excel.