Help! please with variable name problems

I have a program that administers a quiz but the no. of questions in the quiz is variable, qarray holds the questions. I am using card layout and i need to set up a new card for each questions. The number of answer choices to multiple choice questions are also variable and i'm going to have the same sort of problem when i'm creating checkboxes. Is there any way around this. I'm getting an error message variable required but value found.
noOfQuestions = qarray.length;
for(int i=1; i<noOfQuestions; i++)
Card = "Card"+i;
String cardname;
JPanel (Card) = new JPanel();
Card.add(new JLabel("Question "+i));
if(qarray.oftypemc())
Card.add(new JLabel(""+qarray[i].getQuestion()));

Look, some guy invented ARRAYs.
So, do
noOfQuestions = qarray.length;
JPanel[] cards = new JPanel[noOfQuestions];
for(int k=0; k<noOfQuestions; k++) // note: index must start at 0
    cards[k] = new JPanel();
    cards[k].add(new JLabel("Question " + k));
}or better yet
CardLayout cardLayout = new CardLayout(); // cardLayout should be global
JPanel allCards = new JPanel();           // allCards should be global
allCards.setLayout(cardLayout);
JPanel card;
String cardName;
noOfQuestions = qarray.length;
for(int k=0; k<noOfQuestions; k++) // note: index must start at 0
    cardName = "Question " + k;
    card = new JPanel();
    card.add(new JLabel(cardName));
    allCards.add(card, cardName);
}Now, I leave it to you to figure out why cardLayout and allCards should be global fields.

Similar Messages

  • Help Please, with Annoying painting problem.

    Hi:
    I keep running in to this annoying problem:
    Swing Components not being re-drawn properly after:
    Windows turns on the screensaver
    or to a lesser degree if the Java program is Iconified / deiconified.
    Components with Images on them get corrupted and the image is not drawn properly, maybe just the top cm or so, but it is annoying..
    And I can't figure out what or if anything I am doing wrong.
    It happens in a few of my applications.........
    mostly those wher I have overidden paintComponent()
    If someone would like to see if they have the same thing happen, below is an example that demonstrates the problem.
    You will probably need to fiddle with you power settings so that you monitor blanks after 1 min. to avoid having to wait too long.
    Run the program, wait for screen to blank out, bring screen back,...
    If the java picture is not corrupt try re-sizing the JFrame and see what happens.
    I am using Win98SE
    I have Java:
    java version "1.4.2-beta"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
    Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)
    I would appreciate someone trying this out. Even if it doesn't happen for them.
    Or maybe there is a glaring Error in my code.... And if so I could fix it..
    Here is an exmple program to demonstrate this.
    Two classes, The JPanel was obviously meant to do other things but I cut it down..
    The main:
    import java.awt.BorderLayout;
    import java.awt.Container;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
    import java.net.*;
    public class Test extends JFrame
         public Test()
              super("Test");
              Container content = this.getContentPane();
              content.setLayout( new BorderLayout() );
              URL url = null;
              Class ThisClass = this.getClass();
              url=ThisClass.getResource("Background.jpg");
              StarPanel panel = new StarPanel( url );
              content.add( panel , BorderLayout.CENTER );
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.setSize(400,400);
              this.setVisible( true );
         public static void main( String[] args )
              Test Example = new Test();
    }The JComponent - with overrriden paintComponent()
    import java.awt.Image;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.MediaTracker;
    import java.awt.Toolkit;
    import java.net.*;
         cut down version
    public class StarPanel extends JPanel
    private Image image = null;
    private boolean imageLoaded = false;
         public StarPanel( URL imageLocation )
              super();
              this.setOpaque( true );
              loadImage( imageLocation );
         public boolean isOpaque()
              return true;
         public Image getImage()
              return this.image;
         public boolean hasImage()
              return imageLoaded;
         public void loadImage( URL imageLocation )
              boolean goodLoad = true;
              boolean Test = false;
              Toolkit T = this.getToolkit();
              image = T.getImage( imageLocation );
              prepareImage(image, this);
              MediaTracker Tracker = new MediaTracker( this );
              Tracker.addImage( image , 0 );
              try
                   Tracker.waitForID( 0 );
              catch( InterruptedException IE )
                   System.out.println( "Interrupted loading Image for StarPanel: " + IE.getMessage() );
                   goodLoad = false;
              Test = Tracker.isErrorID( 0 );
              if( Test )
                   goodLoad = false;
              if( !goodLoad )
                   imageLoaded = false;
              else
                   imageLoaded = true;
              Tracker = null;
         sans any error checking
         protected void paintComponent(Graphics g)
              super.paintComponent( g );
              Graphics2D g2D = (Graphics2D) g;
              boolean T = g2D.drawImage(this.getImage(), 0, 0, this.getWidth(), this.getHeight(), this );
    }I have tried quite a few different approaches to remove or minimize this problem, and have read everything I can here on paintComponent() and etc
    Help would be appreciated.
    No dukes cos I somehow have less than 0.
    Arrg my code was all neat - before I pasted it in to the code tags.

    I tried your code and did not notice any painting problems. I'm using JDK1.4.1 on Windows 98.
    I don't see any problems with your code. Here is the thread I usually recommend when people want to add an image to a component, in case you want to run another test:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=316074

  • Help please with Sound card problem in CS6

    I have just discovered that after installing AA CS 6...  that the ASIO driver I've had for several years for my Presonus Firebox seems to have disappeared!!!
    I have ASIO selected in  edit >preferences > audio hardware... but in WIN XP Pro "device manager" my FireBox shows up as a "1394 WDM device"  and the driver... although "working properly"... shows up as a WDM driver as well.
    Does CS6 replace the ASIO driver with WDM???
    If anyone can guide me on how to get back to ASIO I would appreciate.  Forgot to mention that ASIO always worked as it should when I was using AA 2.0 and AA CS 5.5
    Many thanks in advance for any help   :-)

    cyberman45 wrote:
    I have ASIO selected in  edit >preferences > audio hardware... but in WIN XP Pro "device manager" my FireBox shows up as a "1394 WDM device"  and the driver... although "working properly"... shows up as a WDM driver as well.
    Does CS6 replace the ASIO driver with WDM???
    As Bob says, Audition doesn't replace drivers. I'm not sure whether the OS actually recognises the presence of an ASIO driver though, because its primary purpose is to bypass as much of the OS as possible, and give software that does recognise it direct low-latency access to the device. So pretty obviously it has nothing to do with Microsoft!

  • Help Please with media pending problem!!

    I've been using PP CS6 for a couple of years on a Rain system with no problems at all.  Yesterday evening I deleted several old files on my scratch disc, one of them I think contained all of the cache files for all the projects on that drive.  Now every project I open it takes forever to load the media, and I get "media pending"  Once it all does load I can't hardly play it back because it keeps locking up.  I have several projects that I have to get out and am really in a bind here, can anyone give me a hand??

    Ronin,
    If we're talking about a laptop, then are you running the 2630 or 2630qm?  Most likely the qm version, no?  It appears that the 2630qm DOES have integrated graphics:
    http://ark.intel.com/products/52219/Intel-Core-i7-2630QM-Processor-6M-Cache-up-to-2_90-GHz
    You ALSO have an NVIDIA card.  Again "Optimus" is simply an "Apple-ism" (like "Retina" or "Flash Storage") for Integrated (aka On-board) graphics working in tandem WITH a more powerful graphics card (i.e. the gtx 560m).  I would take a serious look at disabling it via the instructions in the link I sent previously.  They may not even have thought up the moniker "Optimus" when your laptop was released.  I don't know.  Regardless, when the computer tries to switch between the on-board (power-saving and weak) graphics card to the NVIDIA card, you might experience exactly the type of symptoms you've described.
    By way of example:  Take the Asus g75vx.  It comes stock with a 3630qm chip.  The 3630qm has no option for on-board graphics at all (aka Intel HD 3000, 4000, etc).  The g75vx comes with a gtx 670mx, but if paired with the "wrong" i7 mobile chip, it might just as easily have on-board (Intel HD) graphics, too.
    Another way to check might be to open up Device Manager and see what entries are listed under under Display Adapters.

  • Help please with apache installation problem!!!

    1)I installed Oracle9i Enterprise Edition.
    2)I installed Oracle9iAS standart Edition in separate Home.
    3)Apache HTTP and SSL server servicecould not start.
    I've got 3 errors:
    1.The Apache service named C:\ORACLE\iSuites\Apache\Apache\Apache.exe reported the following error:
    [Wed Aug 22 16:18:53 2001] [error] (2)The system cannot find the file specified: RegQueryValueEx(key System\CurrentControlSet\Services\OracleiSuitesHTTPServer\Parameters) <<<before the error.log file could be opened.
    More information may be available in the error.log file. .
    2.The Apache service named C:\ORACLE\iSuites\Apache\Apache\Apache.exe reported the following error:
    Syntax error on line 14 of c:/oracle/isuites/apache/apache/conf/mod__ose.conf: <<<before the error.log file could be opened.
    More information may be available in the error.log file. .
    3.The Apache service named C:\ORACLE\iSuites\Apache\Apache\Apache.exe reported the following error:
    AuroraService - directive already in effect for this Server <<<before the error.log file could be opened.
    More information may be available in the error.log file. .
    What do I wrong or what do I need to do?
    Thank you in advance
    Alex

    It looks like you have done an installation into a directory that previously contained 9iAS too.
    Look for a file named oracle_apache.conf. It is likely that a line with mod__ose.conf is mentioned twice - remove one line. Save the file. This will solve part of the problem.
    What leaves, your error "1" might indicate that the service was not created because during your prev install it was not removed correctly.
    The installation might contain more errors. Consider uninstalling the software, remove the ORACLE_HOME and services and do a reinstall...

  • Help please with plug in problem

    About 2 weeks ago I began receiving an error message for most every web page I visited, like this: The page “Unable to Load Plug-in. ESPN.com attempted to load an Internet plug-in named “Shockwave Flash”, but the plug-in failed to load successfully."
    I never had any problem like this before, and I think it is linked to one of a few updates (not sure at this point which ones I ran) I downloaded from apple around the same time. I have tried to reinstall shockwave, but none of my downloads will "mount" now. I'm fairly new to macs and a little uneasy about getting in any deeper on my own, even if the answer might be readily apparent to a more sophisticated user. fwiw, I'm running OSX 10.4.3.
    I would appreciate any thoughts that anyone might have in diagnosing this problem. Thank you.

    I set up a new admin user account, logged in, but the problem persists.
    I take this to mean that you still can't mount any downloads. What you're saying is that you can't mount any .dmg file by double-clicking on it. Is that correct? If so, see http://docs.info.apple.com/article.html?artnum=75098 and http://docs.info.apple.com/article.html?artnum=106692 for potential fixes. One other thing to try is reinstall the 10.4.3 Combo update before trying to reinstall Safari or the entire OS.

  • HT1349 The nice man Joseph Shen helped me with my google problem on my iPhone and worked for 2 days and now not working again please help me solve this problem were I can retrieve my messages on the I phone when I am not at home  on my wi Fi is the only t

    The nice man Joseph Shen helped me with my google problem on my iPhone and worked for 2 days and now not working again please help me solve this problem were I can retrieve my messages on the I phone when I am not at home  on my wi Fi is the only time it works correct. Bill. [email protected]  708 752  3667 

    http://lifehacker.com/5852948/what-to-do-if-youve-forgotten-your-iphones-passcod e

  • Please help me with scsi HD Problem

    Please help me with scsi HD Problem.
    Hi for the life of me I cant resolve this.
    I have a ms-6378 ver.3 board with 1.1g AMD
    i could not install windows 2000 on a Seagate 73Gig 68 pin SCSI Drive ultra wid. after giveing up i added a IDE HD and install win2k SP2 and added the SCSI card all still worked ok
    but as soon as i added the hardrive it locks up and it will
    not compleat the load of win2k and tried a smoler drive 18Gig 68 pin SCSI Drive. but it will not load windows 2000. i am stumpt. ;(

    It sounds like an IRQ conflict.  Make sure you diable the primary and secondary channels for the IDE ports to free up the IRQ resources for the SCSI drives.  If you are using a separate SCSI controller, make sure it is in the proper PCI slot and does not share IRQ's with other cards.

  • HI ,We would like to ask you to help us with the following problem

    We would like to ask you to help us with the following problem. As usual we tried to post unmatched received advance payment which is subject to output VAT via transaction SM35. Normally we post the payment to account 501020 (Advances Received from Operating Activities), we generate output VAT by clicking on u201CSimulate Taxu201D. Then we simulate the document and four lines are automatically generated (please see the attached scan of such document posted recently):
    40           510000 (Trade Receivables - Receive from Bank)
    19           501020 (Advances Received from Operating Activities)
    50           400000 (Output Tax (Sales Tax Payable))
    40           405033 (Customer Advances VAT)
    However when we tried to post it today it is not possible and an error message u201CTax clearing account 405033 may not have open item managementu201D appears u2013 please see the scanned printscreen. This did not happen in the past.
    We would appreciate if you could solve it as soon as possible as we still need to post it to period 12.

    Hello
    You execute the t/code FS00 for G/l 405033 and go the control tab select tick in open item mgt under act mgt in co.code.
    Regards
    Avijit

  • Can someone help me with an iCloud problem when I take a picture with my iPhone 4s it some of the times go to my ipad2 but mostly it doesn't can anyone help me out

    Can someone help me with an iCloud problem when I take a picture with my iPhone 4s it some of the times go to my ipad2 but mostly it doesn't can anyone help me out

    I'm assuming you have Photo Stream set up of both devices.  However, it seems many users are experiencing the same as you - my take is that streaming photos is not foolproof yet.

  • Help please with FaceTime. The built in app seems to have disappeared from my iPad2. Bought it in Australia

    Help please with FaceTime. My built in app seems to have disappeared.

    If K Penguin's suggestion doesnt work, you will have to go to you iTunes and do a reset, that is if you do not have it in your back up library.

  • Little help please with forwarding traffic to proxy server!

    hi all, little help please with this error message
    i got this when i ran my code and requested only the home page of the google at my client side !!
    GET / HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
    Accept-Language: en-us
    UA-CPU: x86
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.2; .NET CLR 2.0.50727)
    Host: www.google.com
    Connection: Keep-Alive
    Cookie: PREF=ID=a21457942a93fc67:TB=2:TM=1212883502:LM=1213187620:GM=1:S=H1BYeDQt9622ONKF
    HTTP/1.0 200 OK
    Cache-Control: private, max-age=0
    Date: Fri, 20 Jun 2008 22:43:15 GMT
    Expires: -1
    Content-Type: text/html; charset=UTF-8
    Content-Encoding: gzip
    Server: gws
    Content-Length: 2649
    X-Cache: MISS from linux-e6p8
    X-Cache-Lookup: MISS from linux-e6p8:3128
    Via: 1.0
    Connection: keep-alive
    GET /8SE/11?MI=32d919696b43409cb90ec369fe7aab75&LV=3.1.0.146&AG=T14050&IS=0000&TE=1&TV=tmen-us%7Cts20080620224324%7Crf0%7Csq38%7Cwi133526%7Ceuhttp%3A%2F%2Fwww.google.com%2F HTTP/1.1
    User-Agent: MSN_SL/3.1 Microsoft-Windows/5.1
    Host: g.ceipmsn.com
    HTTP/1.0 403 Forbidden
    Server: squid/2.6.STABLE5
    Date: Sat, 21 Jun 2008 01:46:26 GMT
    Content-Type: text/html
    Content-Length: 1066
    Expires: Sat, 21 Jun 2008 01:46:26 GMT
    X-Squid-Error: ERR_ACCESS_DENIED 0
    X-Cache: MISS from linux-e6p8
    X-Cache-Lookup: NONE from linux-e6p8:3128
    Via: 1.0
    Connection: close
    java.net.SocketException: Broken pipe // this is the error message
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:115)
    at java.io.DataOutputStream.writeBytes(DataOutputStream.java:259)
    at SimpleHttpHandler.run(Test77.java:61)
    at java.lang.Thread.run(Thread.java:595)
    at Test77.main(Test77.java:13)

    please could just tell me what is wrong with my code ! this is the last idea in my G.p and am havin difficulties with that cuz this is the first time dealin with java :( the purpose of my code to forward the http traffic from client to Squid server ( proxy server ) then forward the response from squid server to the clients !
    thanx a lot,
    this is my code :
    import java.io.*;
    import java.net.*;
    public class Test7 {
    public static void main(String[] args) {
    try {
    ServerSocket serverSocket = new ServerSocket(1416);
    while(true){
    System.out.println("Waiting for request");
    Socket socket = serverSocket.accept();
    new Thread(new SimpleHttpHandler(socket)).run();
    socket.close();
    catch (Exception e) {
    e.printStackTrace();
    class SimpleHttpHandler implements Runnable{
    private final static String CLRF = "\r\n";
    private Socket client;
    private DataOutputStream writer;
    private DataOutputStream writer2;
    private BufferedReader reader;
    private BufferedReader reader2;
    public SimpleHttpHandler(Socket client){
    this.client = client;
    public void run(){
    try{
    this.reader = new BufferedReader(
    new InputStreamReader(
    this.client.getInputStream()
    InetAddress ipp=InetAddress.getByName("192.168.6.29"); \\ my squid server
    System.out.println(ipp);
    StringBuffer buffer = new StringBuffer();
    Socket ss=new Socket(ipp,3128);
    this.writer= new DataOutputStream(ss.getOutputStream());
    writer.writeBytes(this.read());
    this.reader2 = new BufferedReader(
    new InputStreamReader(
    ss.getInputStream()
    this.writer2= new DataOutputStream(this.client.getOutputStream());
    writer2.writeBytes(this.read2());
    this.writer2.close();
    this.writer.close();
    this.reader.close();
    this.reader2.close();
    this.client.close();
    catch(Exception e){
    e.printStackTrace();
    private String read() throws IOException{
    String in = "";
    StringBuffer buffer = new StringBuffer();
    while(!(in = this.reader.readLine()).trim().equals("")){
    buffer.append(in + "\n");
    buffer.append(in + "\n");
    System.out.println(buffer.toString());
    return buffer.toString();
    private String read2() throws IOException{
    String in = "";
    StringBuffer buffer = new StringBuffer();
    while(!(in = this.reader2.readLine()).trim().equals("")){
    buffer.append(in + "\n");
    System.out.println(buffer.toString());
    return buffer.toString();
    Edited by: Tareq85 on Jun 20, 2008 5:22 PM

  • What is the best way to remotely access my sister in laws Mac who lives in another city to help her with her computer problems?

    as stated above
    What is the best way to remotely access my sister in laws Mac who lives in another city to help her with her computer problems?

    The best way? Get her to bring it to you, especially if she makes good cakes.
    Apples Back to my Mac isn't really suitable for this - it is designed for a single person who wants their Apple ID on the system. It would mean she would have to share hers with you & you would also have to setup her Apple ID on your Mac - it is messy & causes trouble with iCloud, iTunes etc.
    You can try Messages if she is able to begin a session with you, see the 'invite to share screen' in the menus, weirdly you need to use a service that isn't from Apple.
    Messages (Mavericks): Share your screen
    It may be better if you to setup LogMeIn or GoToMyPC. They should 'dial out' & maintain a constant connection so you can login whenever the Mac is powered up. It won't, require a human to initiate the process at the other end, just be aware that the router may cause issues depending on what is configured, you may need settings to enable automatic port forwarding - it really depend on which option you choose.

  • Can anyone help me with an iWeb problem? I cannot save the site after making changes. I receive this error: "website.sites2 could not be saved"

    Can anyone help me with an iWeb problem? I cannot save the site after making changes. I receive this error: "website.sites2 could not be saved"

    You could try duplicating the Domain.sites2 file and launch this in iWeb. Delete the last page you edited and try saving. If that doesn't work, undo and try deleting another and so on...
    If you can find the problem page you would only have to rebuild it rather than the whole site.
    The other possibility is to create a new site on the same domain file and drag each page in turn down to it from the top site and try to save each time.

  • Can anyone help please with my Time Machine, I have been getting the following message The backup disk image "/Volumes/Mac Backup/Stephen Smith's iMac.sparsebundle" is already in use.

    Can anyone help please with my Time Machine, I have been getting the following message The backup disk image “/Volumes/Mac Backup/Stephen Smith’s iMac.sparsebundle” is already in use.

    See > http://pondini.org/TM/C12.html

Maybe you are looking for