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 11 of 11

Thread: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

  1. #1
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Do you have any specific questions or problems?
    If you don't understand my answer, don't ignore it, ask a question.


  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    yes, the robot moves in all directions, pushes the bomb, there is a red bricked area and compass which I have created code for, however i cant seem to figure out this section: create 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    Task

    Basic System Requirements (Graphical User Interface):
    • 30 x 30 grid of JButton’s or Icon’s.
    • 4 JButton’s for ‘Option 1-3’ and ‘Exit’.
    • 3 JButton’s for ‘Act’, ‘Run’ and ‘Reset’.
    • 9 JButton’s for ‘Forward >’, ‘Backwards <’, ‘Up ^’, ‘Down v’ should move the robot in the appropriate direction by one square for each press (plus 5 blank).
    • The compass icon (JButton) should illustrate the current direction for the robot.
    • 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’.
    • JTextField’s for the current option, location/square and direction of the robot. Use your own square identification method e.g 1 to 273 and N, E etc.
    • Create a JFrame application, which opens to the set size (875 * 550).
    • JFrame title set as "CBombRobot Application".

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    robot moves in all directions, pushes the bomb, there is a red bricked area and compass which I have created code for, however i cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    Task
    Basic System Requirements (Graphical User Interface):
    • 30 x 30 grid of JButton’s or Icon’s.
    • 4 JButton’s for ‘Option 1-3’ and ‘Exit’.
    • 3 JButton’s for ‘Act’, ‘Run’ and ‘Reset’.
    • 9 JButton’s for ‘Forward >’, ‘Backwards <’, ‘Up ^’, ‘Down v’ should move the robot in the appropriate direction by one square for each press (plus 5 blank).
    • The compass icon (JButton) should illustrate the current direction for the robot.
    • 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’.
    • JTextField’s for the current option, location/square and direction of the robot. Use your own square identification method e.g 1 to 273 and N, E etc.
    • Create a JFrame application, which opens to the set size (875 * 550).
    • JFrame title set as "CBombRobot Application".


    <import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.*; //allows access to java.awt.*
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.ImageObserver;
    import java.*;
    import javax.swing.JTextField;
     
    ///////////////////////////////////////////////////////
    import javax.swing.Timer ;
    import javax.management.timer.*;
    ////////////////////////////////////////////////////
      public class CBRobotLewisBC extends JFrame implements ActionListener 
        {	
     
    	 private JPanel jForNavigationPanel;
    	 private JPanel jForNavigationPane;
    	 private JPanel jPNorthEast;
    	 private JPanel jpLewisrobotarea;
     
    	 private JButton jBLeft;
    	 private JButton jButtonUp;
    	 private JButton jBDown;
    	 private JButton jBRight;
    	 private JButton []jBareaRobot = new JButton[273];
    	 private JPanel southpanel, navigationPanel, jPEast;
    	 private JButton jEastButton, jWestButton, jNorthButton,jSouthButton, jCentreButton, jBlankButton;
    	 private JButton jBTheoption1,jBThe_option2,jBThe_option3,jBThe_option4;
    	 private JButton jBThe_compassButton;
    	 private JPanel jPOptionsPanel;
    	 private JPanel jPtoHoldOptionButtons;
    	 private JTextField jTFWhich_Direction1;
     
     
     
    	 int robotIndexPosistion;
     
     
     
     
     
     
     
    	public static void main(String[] args) {
    		CBRobotLewisBC frame = new CBRobotLewisBC();
            frame.setSize(875, 550);
            frame.createGround();
            frame.setResizable(false);
            frame.setLocationRelativeTo(null);
            frame.setIconImage((new ImageIcon("bin/robot.jpg")).getImage());
            frame.setVisible (true);
     
     
     
    	}
     
     
     
    	public void createGround()
    	{
    		Container window = getContentPane();
    		window.setLayout(new BorderLayout());
     
    //------------- Ground	 Panel ------------------------       
      //Creates the jpGround Panel
        jpLewisrobotarea = new JPanel();
        jpLewisrobotarea.setPreferredSize(new Dimension(700, 416));
        jpLewisrobotarea.setLayout(new GridLayout (13,21));
        window.add(jpLewisrobotarea,BorderLayout.CENTER); 
     
     
     
     
     
     
     
        jPEast = new JPanel();//panel for
     
        jPEast.setLayout( new BorderLayout());
     
        jPEast.setPreferredSize(new Dimension(160,300));
     
        window.add(jPEast, BorderLayout.EAST); 
     
     
     buildTheFloor();
     
    jPNorthEast = new JPanel();//panel for
    jPNorthEast.setLayout( new BorderLayout());
    jPEast.add(jPNorthEast, BorderLayout.NORTH);
     
     
     
    jForNavigationPanel = new JPanel();
    jForNavigationPanel.setLayout( new GridLayout(3, 4));
    jForNavigationPanel.setPreferredSize(new Dimension(275,100));	
     
     
     
     
    	  JButton  jBlank = new JButton("");//BLANK BUTTON
          jForNavigationPanel.add(jBlank );//1
     
     
       jButtonUp = new JButton(" ^ ");
       jButtonUp.addActionListener(this);
       jForNavigationPanel.add(jButtonUp);    //2
     
     
     
       JButton  jBlank2 = new JButton("");//BLANK BUTTON
       jForNavigationPanel.add(jBlank2 );//3
     
     
     
     
     
       jBLeft = new JButton(" < ");//4
       jBLeft.addActionListener(this);
       jForNavigationPanel.add(jBLeft);
     
     
       JButton  jBBlank3 = new JButton("");//BLANK BUTTON
       jForNavigationPanel.add(jBBlank3 );//5
     
     
     
       jBRight = new JButton(">");//6
       jBRight.addActionListener(this);
       jForNavigationPanel.add(jBRight);
     
     
     
       JButton  jBBlank4 = new JButton("");//BLANK BUTTON
       jForNavigationPanel.add(jBBlank4 );//7
     
     
     
       jBDown = new JButton(" v ");
       jBDown.addActionListener(this);
       jForNavigationPanel.add(jBDown);//8
     
     
     
       JButton  jBBlank5 = new JButton("");
       jForNavigationPanel.add(jBBlank5 );//9
       jPNorthEast.add(jForNavigationPanel, BorderLayout.SOUTH);
       window.add(jPEast, BorderLayout.EAST); 
     
     
       jPtoHoldOptionButtons = new JPanel();
       jPtoHoldOptionButtons.setLayout(new GridLayout(2, 2));
       jPtoHoldOptionButtons.setPreferredSize(new Dimension(275, 100));
     
     
     
     
     
    	jPOptionsPanel = new JPanel();
    	jPOptionsPanel.setLayout(new BorderLayout());
    	jPOptionsPanel.add(jPtoHoldOptionButtons,BorderLayout.NORTH);
    	jPEast.add(jPOptionsPanel,BorderLayout.SOUTH);
        The_Options();//Display Options
    	compass();
    	}
     
     
     
    	public void The_Options()
    	{
    		jBTheoption1 = new JButton("option 1");//8
    		jBTheoption1.addActionListener(this);
    		jPtoHoldOptionButtons.add(jBTheoption1);
     
    		jBThe_option2 = new JButton("option2");//8
    		jBThe_option2.addActionListener(this);
    		jPtoHoldOptionButtons.add(jBThe_option2);
     
    		jBThe_option3 = new JButton("option3");//8
    		jBThe_option3.addActionListener(this);
    		jPtoHoldOptionButtons.add(jBThe_option3);
     
     
    		jBThe_option4 = new JButton("EXIT");//8
    		jBThe_option4.addActionListener(this);
    		jPtoHoldOptionButtons.add(jBThe_option4);
    	}
     
     
     
    	public void compass()
    	{
    		JPanel jPcompass = new JPanel();
    		jBThe_compassButton = new JButton("");
    		jBThe_compassButton.setIcon(new ImageIcon(getClass().getResource("east.jpg")));
    		jBThe_compassButton.addActionListener(this);
    		jPcompass.add(jBThe_compassButton);
    		jPOptionsPanel.add(jPcompass, BorderLayout.SOUTH); 
     
    		JPanel jPcompass2 = new JPanel();
    		jBThe_compassButton = new JButton("");
    		jBThe_compassButton.setIcon(new ImageIcon(getClass().getResource("north.jpg")));
    		jBThe_compassButton.addActionListener(this);
    		jPcompass2.add(jBThe_compassButton);
    		jPOptionsPanel.add(jPcompass, BorderLayout.SOUTH); 
     
    		JPanel jPcompass3 = new JPanel();
    		jBThe_compassButton = new JButton("");
    		jBThe_compassButton.setIcon(new ImageIcon(getClass().getResource("west.jpg")));
    		jBThe_compassButton.addActionListener(this);
    		jPcompass3.add(jBThe_compassButton);
    		jPOptionsPanel.add(jPcompass, BorderLayout.SOUTH); 
     
    		JPanel jPcompass4 = new JPanel();
    		jBThe_compassButton = new JButton("");
    		jBThe_compassButton.setIcon(new ImageIcon(getClass().getResource("south.jpg")));
    		jBThe_compassButton.addActionListener(this);
    		jPcompass4.add(jBThe_compassButton);
    		jPOptionsPanel.add(jPcompass, BorderLayout.SOUTH); 
     
     
    	}
     
     
    	//Listen for event
    	public void actionPerformed(ActionEvent event) 
        {
        	Object source = event.getSource();  
     
     
     
        	 if (source == jBRight)
             {  
     
     
                   if (jBareaRobot[robotIndexPosistion + 1].getIcon().toString().endsWith("bomb32x32.png") == false) 
                   {
                	   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("paper.jpg")));
                       robotIndexPosistion++; 
                       jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("robot32x32.png")));  
     
     
     
                   }
                   //If Bomb found move bomb
                   if (jBareaRobot[robotIndexPosistion + 1].getIcon().toString().endsWith("bomb32x32.png") == true) 
                   {
                	   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("paper.jpg")));
                       robotIndexPosistion++; 
                       jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("robot32x32.png")));  
                       jBareaRobot[robotIndexPosistion + 1].setIcon(new ImageIcon(getClass().getResource("bomb32x32.png")));
     
                   }
     
     
     
             }    
     
     
        	 if (source == jBLeft)
             {  
               if(jBareaRobot[robotIndexPosistion-1].getIcon()!=jBareaRobot[101].getIcon())
                   {     
                   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("paper.jpg")));
                   robotIndexPosistion--; 
                   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("robot32x32Left.png")));   
                   }
             } 
     
     
     
        	 if (source == jButtonUp)
             {  
               if(jBareaRobot[robotIndexPosistion-21].getIcon()!=jBareaRobot[101].getIcon())
                   {     
                   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("paper.jpg")));
                   robotIndexPosistion=robotIndexPosistion-21; 
                   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("robot32x32Up.png")));   
                   }
             } 
     
     
     
     
        	 if (source == jBDown)
             {  
               if(jBareaRobot[robotIndexPosistion+21].getIcon()!=jBareaRobot[101].getIcon())
                   {     
                   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("paper.jpg")));
                   robotIndexPosistion=robotIndexPosistion+21; 
                   jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("robot32x32Down.png")));   
                   }
             } 
     
     
     
     
        }
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    	//creates Buttons for floor which adds to the frame
        public void buildTheFloor()
        {
        	robotIndexPosistion =189;
        	//Add Buttons";
        	for (int i=0; i<jBareaRobot.length; i++)
     
            {
            	jBareaRobot[i] = new JButton("");
            	jBareaRobot[i].setIcon(new ImageIcon(getClass().getResource("paper.jpg")));
            	jBareaRobot[i].setBorderPainted(false);
                jpLewisrobotarea.add(jBareaRobot[i]);
     
            }
        	jBareaRobot[robotIndexPosistion].setIcon(new ImageIcon(getClass().getResource("robot32x32.png"))); 
        	//
        	jBareaRobot[0].setIcon(new ImageIcon(getClass().getResource("paper.jpg")));
        	jBareaRobot[32].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[53].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[74].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[95].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[116].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[137].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[158].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[179].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[200].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[90].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[111].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[132].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[153].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[174].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[195].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[216].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[237].setIcon(new ImageIcon(getClass().getResource("rock32x32.png")));
        	jBareaRobot[190].setIcon(new ImageIcon(getClass().getResource("bomb32x32.png")));
        	jBareaRobot[78].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[79].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[80].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[81].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[82].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[99].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[120].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[141].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[142].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[143].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[144].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[145].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[103].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
        	jBareaRobot[124].setIcon(new ImageIcon(getClass().getResource("bricks.png")));
     
     
     
        }
     
    }
    >

    replies would greatly appreciated

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

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    create 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot
    What is the problem with creating those JLabels?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    I dont know how to create jlabels and i cant remember bieng taught it in lectures, could you please help me?? as i have got my assignment due at 23.59pm today and thats what i need, been trying to figure it out for hours, (I know i look like a noob)

    would greatly appreciate it

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

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    a JLabel is just another component that can be added to the GUI to display text or an image.
    Create an instance of the JLabel and add it to a container just like is done with a JButton component.

    See the tutorial: How to Use Labels (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    do these jlabels have to be created as part of a different program then imported??

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

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    Treat them the same as the JButtons or other components added to the GUI.
    Read the tutorial.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    thank you, ill take a quick look at the tutorial

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

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: cant seem to figure out this section: 3 JLabel’s for’Option’, ‘Square’ and ‘Direction’, & JTextField’s for the current option, location/square and direction of the robot

    sorry about that accidently posed it twice because i didn't think it went through the first time

Similar Threads

  1. [Y/N] Option
    By OOO in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 25th, 2011, 10:19 PM
  2. Conways Game of Life. Long Death option. Please help..
    By byako in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 9th, 2011, 08:49 AM
  3. Buffered Reader to J Option
    By jk_0821 in forum Collections and Generics
    Replies: 13
    Last Post: July 19th, 2010, 03:14 PM
  4. Is thread the best option?
    By 256mxr in forum Threads
    Replies: 1
    Last Post: May 22nd, 2010, 08:24 PM