Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 22 of 22

Thread: Working on a phdgets Project for Computer Science Need some Help.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Working on a phdgets Project for Computer Science Need some Help.

    For my project i have 3 light sensor's labeled 1,2 and 3. Eventually I would to display a screen with a Play button, after the button is pressed i want it to randomly display A picture of the Number(1-3) every three seconds indicating which one to shoot with the laser pointer gun. When one of the sensor's is shot I want to add 5 points to the score. I want to display the score on the same panel as the random Number Images. Soo far I have tried making a program to display the Random images, but I'm sure there is a better way of accomplishing this other than what i have used. Could someone please show me?


    Here are the images I want to display:

    1.jpg2.jpg3.jpg

       import java.util.*;
       import javax.swing.event.*;
       import javax.swing.*;
       import java.awt.*;
       import java.awt.image.*;
       import java.awt.event.*;
       import java.util.Random;
       import javax.swing.Timer;
     
    public class TimerExample extends JFrame
       {
          Random rand = new Random();
          static int currRand;
          private ImageIcon image1;
          private ImageIcon image2;
          private ImageIcon image3;
          private JPanel panel;
    		private JPanel panel2;
    		private JPanel panel3;
    		private JLabel label2;
    		private JLabel label3;
          private JLabel label;
     
     
     
          public TimerExample() 
          {
             setSize(1000,1000);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setTitle("RandomPictureTimer");
     
             ImageIcon image1 = new ImageIcon("1.png");
          	ImageIcon image2 = new ImageIcon("2.png");
          	ImageIcon image3 = new ImageIcon("3.png");
     
     
     
             label= new JLabel(image1);
    			label2 = new JLabel(image2);
    			label3= new JLabel(image3);
             panel = new JPanel();
    			panel2 = new JPanel();
    			panel3= new JPanel();
     
            Timer timer = new Timer(3000,new TimerListener());
             timer.start();
     
                while(true)
                   if(currRand==2) 
                   {
                      System.out.println("3");
    						panel3.add(label3);
    						add(panel3);
    						setVisible(true);
     
                   }
                   else if (currRand ==1)
                   {
                      System.out.println("2");
    						panel2.add(label2);
    						add(panel2);
    						setVisible(true);
     
                   }
                   else if (currRand==0)
                   {
                      System.out.println("1");
    						panel.add(label);
    						add(panel);
    						setVisible(true);
     
                   }
     
          }
     
          private class TimerListener implements ActionListener
        	{
             public void actionPerformed(ActionEvent e)
            {
                currRand = rand.nextInt(3);
     
     
     
             }
          }
     
          public static void main(String args[])
          {
             new TimerExample();
          }
       }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    What parts of the code are you having problems with?
    The timer?
    The changing of the components being shown?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    I am having problems with both the components being shown and the timer. it seems that the Numbers are being displayed 3000 times for every 3 seconds, and i would like it to only display the image once every three seconds.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Get rid of the while() loop. Use only one label and change its icon in the timer listener method.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Alright thanks think i got it:

       import java.util.*;
       import javax.swing.event.*;
       import javax.swing.*;
       import java.awt.*;
       import java.awt.image.*;
       import java.awt.event.*;
       import java.util.Random;
       import javax.swing.Timer;
     
    public class TimerExample extends JFrame
       {
          Random rand = new Random();
          static int currRand;
          private ImageIcon image1;
          private ImageIcon image2;
          private ImageIcon image3;
          private JPanel panel;
    		private JPanel panel2;
    		private JPanel panel3;
    		private JLabel label2;
    		private JLabel label3;
          private JLabel label;
     
     
     
          public TimerExample() 
          {
             setSize(1000,1000);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setTitle("RandomPictureTimer");
     
             ImageIcon image1 = new ImageIcon("");
     
             label= new JLabel(image1);
             panel = new JPanel();
     
            Timer timer = new Timer(3000,new TimerListener());
             timer.start();
     
    			panel.add(label);
    			add(panel);
    			setVisible(true);
     
     
          }
       	public void paint(Graphics g)
    		{
    			super.paint(g);
    			image1.paintIcon(this,g,100,100);
    		}
          private class TimerListener implements ActionListener
        	{
             public void actionPerformed(ActionEvent e)
            {
                currRand = rand.nextInt(3);
    				 if(currRand==2) 
                   {
                      System.out.println("3");
    						image1= new ImageIcon("3.png");
    						repaint();
                   }
                   else if (currRand ==1)
                   {
                      System.out.println("2");
    						image1 = new ImageIcon("2.png");
    						repaint();
     
     
                   }
                   else if (currRand==0)
                   {
                      System.out.println("1");
    						//label= new JLabel(image1);
    						image1= new ImageIcon("1.png");
    						repaint();
     
                   }
     
     
             }
          }
     
          public static void main(String args[])
          {
             new TimerExample();
          }
       }

    is there a way to make it so that the same number is not generated twice in a row?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    make it so that the same number is not generated twice in a row?
    Keep track of the numbers as they are generated and change it if the same as last one.

    You should only load the images one time and use them in the listener.
    Don't load them every call to the listener method.

    You should NOT override the paint() method for a Swing class.
    There is no need to draw images.
    use the label class's setIcon() method.
    Last edited by Norm; April 24th, 2012 at 03:34 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Alright I tried doing what you said with trying to keep track of the numbers as they are generated but i am still getting numbers twice in a row, I also tried using the setIcon() method for the pictures but I'm doing something wrong there too... Sorry for being such a java noob.

    this is what i tried, but still cant seem to get it:
        import java.util.*;
       import javax.swing.event.*;
       import javax.swing.*;
       import java.awt.*;
       import java.awt.image.*;
       import java.awt.event.*;
       import java.util.Random;
       import javax.swing.Timer;
     
    public class TimerExample extends JFrame
       {
          Random rand = new Random();
          private int currRand;
          private ImageIcon image1;
    		private ImageIcon image2;
    		private ImageIcon image3;
          private JPanel panel;
          private JLabel label;
    		private int noDoubles;
     
     
     
          public TimerExample() 
          {
             setSize(1000,1000);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setTitle("RandomPictureTimer");
     
             ImageIcon image1 = new ImageIcon("1.png");
    			ImageIcon image2 = new ImageIcon("2.png");
    			ImageIcon image3 = new ImageIcon("3.png");
     
             label= new JLabel();
             panel = new JPanel();
     
            Timer timer = new Timer(3000,new TimerListener());
             timer.start();
     
    			panel.add(label);
    			add(panel);
    			setVisible(true);
     
     
          }
          private class TimerListener implements ActionListener
        	{
             public void actionPerformed(ActionEvent e)
            {
                currRand = rand.nextInt(2);
    				noDoubles = currRand;
     
    				if(currRand==noDoubles)//Attempt to create no Doubles?
    					{
    						currRand = rand.nextInt(2);	
    					}
     
     
    				 if(noDoubles==2) 
                   {
                      System.out.println("3");
    						//image1= new ImageIcon("3.png");
    						label.setIcon(image3);
    						repaint();
                   }
                   else if (noDoubles ==1)
                   {
                      System.out.println("2");
    						//image1 = new ImageIcon("2.png");
    						label.setIcon(image2);
    						repaint();
                   }
                   else if (noDoubles==0)
                   {
                      System.out.println("1");
    						//image1= new ImageIcon("1.png");
    						label.setIcon(image3);
    						repaint();
                   }
     
     
             }
          }
     
          public static void main(String args[])
          {
             new TimerExample();
          }
       }

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

                    currRand = rand.nextInt(2);
       		noDoubles = currRand;
     
    		if(currRand==noDoubles
    When will the if test every be false? You've just set the two variables =

    What happens when you execute the code? What do you see?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Alright i get what you're saying, I see that by setting noDoubles= currRand and then using the if statement directly after i am not really accomplishing anything, but i am not sure how to solve this problem.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Use some logic. What number do you want to save so you do not repeat it? When is that number known for sure? Certainly not when you get a new random number.
    What about after you have determined that it is a new unique number?

    What happens when you execute the code? What do you see?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Okay... I want to save the last number generated by the Random and check to see if it is the same as the one being generated, if it is then generate a new number but if it isnt continue on with the program, but i am not sure how to do this

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Ok that sounds reasonable. Save the last one used and check it against the one generated by nextInt() to see if different. If the same, get a new one. If different use it and save for testing next time.

    What happens when you execute the code? What do you see?
    What happens when you execute the code? What do you see?
    What happens when you execute the code? What do you see?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Alright I got it, but the Images are not showing up.

    *    import java.util.*;
       import javax.swing.event.*;
       import javax.swing.*;
       import java.awt.*;
       import java.awt.image.*;
       import java.awt.event.*;
       import java.util.Random;
       import javax.swing.Timer;
     
    public class TimerExample extends JFrame
       {
          Random rand = new Random();
          private int currRand;
          private ImageIcon image1;
    		private ImageIcon image2;
    		private ImageIcon image3;
          private JPanel panel;
          private JLabel label;
    		private int noDoubles;
     
     
     
          public TimerExample() 
          {
             setSize(1000,1000);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setTitle("RandomPictureTimer");
     
             ImageIcon image1 = new ImageIcon("1.png");
    			ImageIcon image2 = new ImageIcon("2.png");
    			ImageIcon image3 = new ImageIcon("3.png");
     
             label= new JLabel();
             panel = new JPanel();
     
            Timer timer = new Timer(3000,new TimerListener());
             timer.start();
     
    			panel.add(label);
    			add(panel);
    			setVisible(true);
     
     
          }
          private class TimerListener implements ActionListener
        	{
             public void actionPerformed(ActionEvent e)
            {
                noDoubles=rand.nextInt(3);
     
    					if(currRand==noDoubles)
    					{
     
    							noDoubles=rand.nextInt(3);
    					}
    					else
    					{
    						currRand = noDoubles;
    					 if(currRand==3) 
    		               {
    		                  System.out.println("3");
    								//image1= new ImageIcon("3.png");
    								label.setIcon(image3);
    								repaint();
    		               }
    		               else if (currRand ==2)
    		               {
    		                  System.out.println("2");
    								//image1 = new ImageIcon("2.png");
    								label.setIcon(image2);
    								repaint();
    		               }
    		               else if (currRand==1)
    		               {
    		                  System.out.println("1");
    								//image1= new ImageIcon("1.png");
    								label.setIcon(image3);
    								repaint();
    		               }
    						}
     
             }
          }
     
          public static void main(String args[])
          {
             new TimerExample();
          }
       }
    Last edited by Tallonejosh; April 24th, 2012 at 05:33 PM.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    What is the value of image1 etc in the listener method when you try to use them?

    You should initialize noDoubles with an invalid value.

    Your use of currRand is confusing. I'd expect it to be the value from the nextInt() method. The current value. But it looks like it is the value used last time.
    Last edited by Norm; April 24th, 2012 at 05:59 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Alright lol got everything working, sorry if i seem completely retarded I've got alot to do this week.

    Here is what ive got soo far:

       import java.util.*;
       import javax.swing.event.*;
       import javax.swing.*;
       import java.awt.*;
    	import com.phidgets.*;
    	import com.phidgets.event.*;
       import java.awt.image.*;
       import java.awt.event.*;
       import java.util.Random;
       import javax.swing.Timer;
     
    public class TimerExample extends JFrame
       {
     
          private JPanel panel;
          private JLabel label;
     
    		//Random Display
    		private int noDoubles=-1;
    		Random rand = new Random();
          private int currRand;
          private ImageIcon image1;
    		private ImageIcon image2;
    		private ImageIcon image3;
     
     
    		//InterFace + Phidgets
    		InterfaceKitPhidget ik;
    		private int port;
    		private int value;
     
    		//Score
    		private int score;
     
     
     
          public TimerExample() 
          {
             setSize(1000,1000);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setTitle("RandomPictureTimer");
     
             ImageIcon image1 = new ImageIcon("1.png");
    			ImageIcon image2 = new ImageIcon("2.png");
    			ImageIcon image3 = new ImageIcon("3.png");
     
             label= new JLabel();
             panel = new JPanel();
     
            Timer timer = new Timer(3000,new TimerListener());
             timer.start();
    			panel.add(label);
    			add(panel);
    			add("Score" +score);
     
    			try
    			{
    			ik = new InterfaceKitPhidget();
    			ik.openAny(); //Open interface attached
     
    			ik.addSensorChangeListener( new InterfaceSensorChangeListener()); 
    	      //Wait for the device to be attached
    	      System.out.println("waiting for InterfaceKit attachment...");
    	      ik.waitForAttachment();
    	      System.out.println(ik.getDeviceName());
    			}
    		catch (PhidgetException e)
    			{   
    		 		System.out.println("Phidget Exception Generated");
    		      e.printStackTrace();
    			}
     
     
    			setVisible(true);
     
     
          }
    		public void paint(Graphics g)
    		{
    			super.paint(g)
    		}
          private class TimerListener implements ActionListener
        	{
             public void actionPerformed(ActionEvent e)
            {
     
    		 do {
        				currRand = rand.nextInt(3);
    			  }
    			while(currRand == noDoubles);
    				noDoubles = currRand;
     
    						if(currRand==0) 
    		               {
    		                  //System.out.println("3");
    								image3= new ImageIcon("3.png");
    								label.setIcon(image3);
    								repaint();
    		               }
    		               else if (currRand ==2)
    		               {
    		                  //System.out.println("2");
    								image2 = new ImageIcon("2.png");
    								label.setIcon(image2);
    								repaint();
    		               }
    		               else if (currRand==1)
    		               {
    		                 // System.out.println("1");
    								image1= new ImageIcon("1.png");
    								label.setIcon(image1);
    								repaint();
    		               }
     
             }
          }
         private class InterfaceSensorChangeListener implements SensorChangeListener
    {    public void sensorChanged(SensorChangeEvent se)
         {			
               // Get the port number of the analog sensor that has changed.
               port = se.getIndex();
     
               //Get the value of the sensor. 
                value = se.getValue();
     
    				if((port==0) && (value>200)&&(currRand ==0))
    					score +=5;
    				if((port==1) && (value>200)&&(currRand==2))
    					score+=5;
    				if((port==2) && (value>200)&&(currRand==1))
    					score +=5;
     
     
     
               //You must know where each sensor has been attached to the interface kit
               System.out.println("Sensor in port: " + port + "has the value: " + value);
    			  //System.out.println("Score: "+score);
     
    		}
    }
     
          public static void main(String args[])
          {
             new TimerExample();
          }
       }

    now, what would be the simplest way to display the score on the JFrame?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    You should read the image files once before using them and NOT read them every time you use them.
    Your code appears to read in the image files in two places????

    way to display the score on the JFrame
    Add a JLabel and change its text.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Alright I added a Jlabel but it doesnt update the score, how do i get it to update the score everytime the player scores a point?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Post the code you are having problems with.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

       import java.util.*;
       import javax.swing.event.*;
       import javax.swing.*;
       import java.awt.*;
    	import com.phidgets.*;
    	import com.phidgets.event.*;
       import java.awt.image.*;
       import java.awt.event.*;
       import java.util.Random;
       import javax.swing.Timer;
     
    public class TargetShooter extends JFrame
       {
     
          private JPanel panel;
          private JLabel label;
     
    		//Random Display
    		private int noDoubles=-1;
    		Random rand = new Random();
          private int currRand;
          private ImageIcon image1;
    		private ImageIcon image2;
    		private ImageIcon image3;
     
    		//Winner
    		private ImageIcon winner;
     
    		//InterFace + Phidgets
    		InterfaceKitPhidget ik;
    		private int port;
    		private int value;
     
    		//Score
    		private int score;
    		private JLabel scoreBoard;
    		private int count=0;
     
     
     
          public TargetShooter() 
          {
             setSize(1000,1000);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             setTitle("Target Shooter ");
     
     
     
             label= new JLabel();
             panel = new JPanel();
     
            Timer timer = new Timer(4000,new TimerListener());
             timer.start();
    			panel.add(label);
     
     
     
    			scoreBoard=new JLabel("Score: " + score);
    			panel.add(scoreBoard, BorderLayout.SOUTH);
    			add(panel);
     
     
    			try
    			{
    			ik = new InterfaceKitPhidget();
    			ik.openAny(); //Open interface attached
     
    			ik.addSensorChangeListener( new InterfaceSensorChangeListener()); 
    	      //Wait for the device to be attached
    	      System.out.println("waiting for InterfaceKit attachment...");
    	      ik.waitForAttachment();
    	      System.out.println(ik.getDeviceName());
    			}
    		catch (PhidgetException e)
    			{   
    		 		System.out.println("Phidget Exception Generated");
    		      e.printStackTrace();
    			}
     
     
    			setVisible(true);
     
     
          }
          private class TimerListener implements ActionListener
        	{
             public void actionPerformed(ActionEvent e)
            {
     
    		 do {
        				currRand = rand.nextInt(3);
    			  }
    			while(currRand == noDoubles);
    				noDoubles = currRand;
     
    						if(currRand==0) 
    		               {
    		                  //System.out.println("3");
    								image3= new ImageIcon("3.png");
    								label.setIcon(image3);
    								scoreBoard.repaint();
    								count++;
    		               }
    		               else if (currRand ==2)
    		               {
    		                  //System.out.println("2");
    								image2 = new ImageIcon("2.png");
    								label.setIcon(image2);
    								scoreBoard.repaint();
    								count++;
    		               }
    		               else if (currRand==1)
    		               {
    		                 // System.out.println("1");
    								image1= new ImageIcon("1.png");
    								label.setIcon(image1);
    								scoreBoard.repaint();
    								count++;
    		               }
     
     
             }
          }
         private class InterfaceSensorChangeListener implements SensorChangeListener
    {    public void sensorChanged(SensorChangeEvent se)
         {			
               // Get the port number of the analog sensor that has changed.
               port = se.getIndex();
     
               //Get the value of the sensor. 
                value = se.getValue();
     
    				if((port==0) && (value>=10)&&(currRand ==0))
    					score +=5;
    				if((port==1) && (value>=10)&&(currRand==2))
    					score+=5;
    				if((port==2) && (value>=10)&&(currRand==1))
    					score +=5;
     
     
     
     
               //You must know where each sensor has been attached to the interface kit
               System.out.println("Sensor in port: " + port + "has the value: " + value);
    			  //System.out.println("Score: "+score);
     
    				//
    						}
    }
     
          public static void main(String args[])
          {
             new TargetShooter();
          }
       }

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    Where do you change the text being shown in the JLabel? The code sets it one time when it creates it:
    scoreBoard=new JLabel("Score: " + score);
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    I want to update the int variable named score.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Working on a phdgets Project for Computer Science Need some Help.

    I want to update the int variable named score.
    This statement does that:
    score +=5;

    How will that change what is shown in the JLabel? You have to call a JLabel method to change its contents.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. AP computer science questions
    By svo in forum Java Theory & Questions
    Replies: 1
    Last Post: April 7th, 2012, 02:24 PM
  2. AP computer science questions
    By svo in forum Java Theory & Questions
    Replies: 1
    Last Post: April 6th, 2012, 11:32 PM
  3. need help in AP Computer Science!
    By eechord in forum Member Introductions
    Replies: 3
    Last Post: October 7th, 2011, 09:57 AM
  4. Replies: 1
    Last Post: March 11th, 2011, 02:11 PM
  5. computer science help
    By hairyjewbear in forum Algorithms & Recursion
    Replies: 6
    Last Post: November 4th, 2010, 04:05 PM