True if circle is drawn from left of applet private

This preview shows page 2 - 4 out of 4 pages.

/** true if circle is drawn from left of applet */ private boolean fromLeft; /** x,y position of the circle*/ private int xPos, yPos; public void init() { xPosT = new TextField(5); //set up TextFields and Buttons add(xPosT); yPosT = new TextField(5); add(yPosT); fromLeftB = new Button("From Left"); fromLeftB.addActionListener(this); add(fromLeftB); fromRightB = new Button("From Right"); fromRightB.addActionListener(this); add(fromRightB); xPos = 100; yPos = 100; fromLeft = false;
Image of page 2

Subscribe to view the full document.

415.101AC Test January 31, 2000 page 3 } //end of init() method public void actionPerformed(ActionEvent e){ if (e.getSource() == fromLeftB){ fromLeft = true; } else { fromLeft = false; } repaint(); }//end of actionPerformed() method public void paint(Graphics g){ int x, y; x = Integer.parseInt(xPosT.getText()); y = Integer.parseInt(yPosT.getText()); if (fromLeft){ g.setColor(Color.blue); g.fillOval(x,y,SIZE,SIZE); } else { x = APP_WIDTH - x - SIZE; g.setColor(Color.red); g.fillOval(x,y,SIZE,SIZE); } }//end of paint() method }//end of Applet Q.8 (7 marks) public class Q8{ public static void main(String args[]) { int nItems; // number of items int totalPaid; // total paid by user int perItemC; //cost per item int totalC; //total cost of items int change; //change if there is any int need; //amount needed if user has not paid enou System.out.print("Number of Items required: "); nItems = Keyboard.readInt(); System.out.print("Cost per Item: $"); perItemC = Keyboard.readInt(); System.out.print("Total paid in: $");
Image of page 3
Image of page 4
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • public void, static final int

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern