5 Replies - 417 Views - Last Post: 03 May 2013 - 08:49 PM Rate Topic: -----

#1 dstevens  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 02-February 13

OR operator and >= operators

Posted 01 May 2013 - 05:34 PM

I have copied a program from my textbook for a project due and is word for word just like the book. It is giving me an error like this....
error given.....
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
The operator >= is undefined for the argument type(s) boolean, int
Syntax error on token "||", delete this token
The operator >= is undefined for the argument type(s) boolean, int
Syntax error on token "||", delete this token

at ReboundPanel$ReboundListener.actionPerformed(ReboundPanel.java:41)

Please help

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ReboundPanel extends JPanel
{
	private final int WIDTH = 300, HEIGHT = 100;
	private final int DELAY = 20, IMAGE_SIZE = 35;
	
	private ImageIcon image;
	private Timer timer;
	private int x, y, moveX, moveY;
	
	public ReboundPanel()
	{
		timer = new Timer(DELAY, new ReboundListener());
		
		image = new ImageIcon ("happyFacce.gif");
		
		x = 0;
		y = 40;
		moveX = moveY = 3;
		
		setPreferredSize (new Dimension(WIDTH, HEIGHT));
		setBackground (Color.black);
		timer.start();
	}
	public void paintComponent(Graphics page)
	{
		super.paintComponent(page);
		image.paintIcon(this,  page, x, y);
	}
	
	private class ReboundListener implements ActionListener
	{
		public void actionPerformed (ActionEvent event)
		{
			x += moveX;
			y += moveY;
			
			if (x <= || x >= WIDTH-IMAGE_SIZE)
				moveX = moveX * -1;
			
			if (y <=||y >= HEIGHT-IMAGE_SIZE)
				moveY = moveY * -1;
			repaint();
		}
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: OR operator and >= operators

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: OR operator and >= operators

Posted 01 May 2013 - 05:37 PM

This line (as indicated by the error message) is just wrong:

if (x <= || x >= WIDTH-IMAGE_SIZE)

Check the source code in the book again and look for typos.
Was This Post Helpful? 1
  • +
  • -

#3 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: OR operator and >= operators

Posted 01 May 2013 - 08:12 PM

Quote

I have copied a program from my textbook for a project due and is word for word just like the book.


We generally frown upon academic disintegrity, which goes hand-in-hand with our homework policy. Know the risks.

Further Reading:
- Shambles > free, online plagarism detector
- Independent > Plagiarism detectors catch 45,000 British students
- I.A.C.I.S. > [PDF] Does the computer programming student understand what constitutes plagiarism?

This post has been edited by Gungnir: 01 May 2013 - 08:13 PM

Was This Post Helpful? 0
  • +
  • -

#4 dstevens  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 02-February 13

Re: OR operator and >= operators

Posted 02 May 2013 - 05:39 PM

I would just like to say, It was an assignment given by the professor and instructed to enter the code given into our java programs(ie: eclipse) So I don't know what you mean by Plagirism.

At this time I would like to say I found the error in this post. the error was the following...
public void actionPerformed (ActionEvent event)
		{
			x += moveX;
			y += moveY;
			
			if (x <= 0 || x >= WIDTH-IMAGE_SIZE)
				moveX = moveX * -1;
			
			if (y <= 0 || y >= HEIGHT-IMAGE_SIZE)
				moveY = moveY * -1;
			repaint();
		}


I would like to know what I am doing wrong with this program, It is suppose to have a happyface bouncing around and I have nothing. can someone please explain to me why it is not working? Please help.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: OR operator and >= operators

Posted 02 May 2013 - 05:49 PM

don't really understand how a X coordinate can end up being < 0 while doing a drawing

How can moveX be switch to -moveX if the X < 0 or > maxValue
may be if >maxValue but surely noy if < 0

as you already did a big mistake cut & pastingthe actual code, why don't you try to start again ?
Was This Post Helpful? 0
  • +
  • -

#6 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: OR operator and >= operators

Posted 03 May 2013 - 08:49 PM

Quote

I would just like to say, It was an assignment given by the professor and instructed to enter the code given into our java programs(ie: eclipse) So I don't know what you mean by Plagirism.

At the risk of another Posted Image vote, I didn't ask whether or not your professor considered it plagiarism. You're being graded on someone elses work, yes?

Quote

I have copied a program from my textbook for a project due and is word for word just like the book.

That's what I thought.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1