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

Thread: Help with coding

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with coding

    im a complete novice programmer and am not great at it. i have to create a program that allows the user to move the dirrection a set of eyes are looking on screen.
    i have buttons created and possitioned and eyes drawn. im not 100% sure what code to put behind the buttons and how to do it. help with it would be great. bellow is the code i have already done.
    import javax.swing.*;   
     
    import java.awt.*;
    import java.awt.event.*;
     
    public class RandomCircleInnerAns implements ActionListener{
     
     
    	JFrame frame1 = new JFrame();
     
    	public static void main(String [] args) {
     
    		RandomCircleInnerAns RCA = new RandomCircleInnerAns();
    		RCA.go1();
     
    	}
     
     
     
    	public void go1(){
     
     
     
    		JButton button = new JButton("LOOK LEFT");
    		JButton button1 = new JButton("LOOK RIGHT");
    		JButton button2 = new JButton("LOOK DOWN");
    		JButton button3 = new JButton("LOOK UP");
    		eye drawPanel = new eye();
    		boolean Button1;
    		boolean Button2;
    		boolean Button3;
    		boolean Button4;
     
     
     
    		frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    		frame1.getContentPane().add(BorderLayout.CENTER,drawPanel);
    		frame1.getContentPane().add(BorderLayout.NORTH,button3);
    		frame1.getContentPane().add(BorderLayout.SOUTH,button2);
    		frame1.getContentPane().add(BorderLayout.EAST,button1);
    		frame1.getContentPane().add(BorderLayout.WEST,button);
     
     
    		frame1.setSize(600,600);
    		frame1.setVisible(true);
     
     
    }
     
    	public void actionPerformed(ActionEvent event) {
    		frame1.repaint();
    	}
     
    	class eye extends JPanel { //inner class definition
     
    		public void paintComponent(Graphics g){
     
     
    		{	  
    		  	g.setColor(Color.white);
    			g.fillRect(0, 0, 600, 600);
    			g.setColor(Color.blue);
    			g.drawOval(30, 60, 130, 130);
    			g.setColor(Color.blue);
    			g.drawOval(180,60,130,130);
    			g.setColor(Color.black);
    			g.fillOval(73,96,50,50);
    			g.setColor(Color.black);
    			g.fillOval(223,96,50,50);
     
     
    		}
     
     
    		}
    		//end paintComponent
    	}//end inner class
    	}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with coding

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

    what code to put behind the buttons
    Can you describe what the code in the listeners should do? Be specific describing what variables need to be changed for the desired results.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with coding

    they should allow me to move the inner eye left,right etc.so if i select look left button, it will move to the left

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with coding

    What variables would the code have to check and to change to do that?

    The hardcoded values in the paintComponent method will have to be changed to be variables so the listener method can see and change their values.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help with some coding
    By Firearrow5235 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: April 13th, 2013, 06:57 AM
  2. [SOLVED] I need help with my coding
    By knockturnal22 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 16th, 2012, 04:19 PM
  3. Need Help With Coding
    By noles227 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2012, 07:35 PM
  4. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  5. Need your help to coding
    By Tony_nguyen19 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 14th, 2011, 08:58 AM

Tags for this Thread