Question:
Help finding syntax errors in java?
?
2010-10-11 19:50:17 UTC
I need help finding syntax errors in this program so it will run. can someone help me find any(or all) of them?



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

public class MovingDisk extends JPanel
implements ActionListener
{
private int time;

public MovingDisk()
{
time = 0
Timer clock = new Timer(30, this);
clock.start;
}

public void paintComponent(Graphics g)
{
int x = 150 - (int)(100 * Math.cos(0.005 * Math.PI * time));
int y = 130 - (int)75 * Math.sin(0.005 * Math.PI * time));
int r = 20;

Color sky;
if (y > 130) sky = Color.BLACK
else sky = Color.CYAN;
setBackground(sky);
super.paintComponent(g);

g.setColor(Color.ORANGE);
g.fillOval(x - r, y - r, 2*r, 2*r);
}

public void actionPerformed(ActionEvent e)
{
time++;
repaint();
}

public static void main(String args)
{
JFrame w = new JFrame("Moving Disk);
w.setSize(300, 150);
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = w.getContentPane();
c.add(new movingDisk());
w.setResizable(false);
w.setVisible(true);
}
}
Four answers:
err
2010-10-11 19:57:42 UTC
import java.awt.*;

import java.awt.event*; -- error here should be event.*

import javax.swing.*;



public class MovingDisk extends JPanel

implements ActionListener

{

private int time;



public MovingDisk()

{

time = 0 // missing semicolon

Timer clock = new Timer(30, this);

clock.start; // should be clock.start();

}



public void paintComponent(Graphics g)

{

int x = 150 - (int)(100 * Math.cos(0.005 * Math.PI * time));

int y = 130 - (int)75 * Math.sin(0.005 * Math.PI * time)); // might raise a cast error

// put a ( before 75

int r = 20;



Color sky;

if (y > 130) sky = Color.BLACK // missing semicolon

else sky = Color.CYAN;

setBackground(sky);

super.paintComponent(g);



g.setColor(Color.ORANGE);

g.fillOval(x - r, y - r, 2*r, 2*r);

}



public void actionPerformed(ActionEvent e)

{

time++;

repaint();

}



public static void main(String args)

{

JFrame w = new JFrame("Moving Disk); // missing double quote on Moving Disk

w.setSize(300, 150);

w.setDefaultCloseOperation(JFrame.EXIT_O…

Container c = w.getContentPane();

c.add(new movingDisk());

w.setResizable(false);

w.setVisible(true);

}

}
Stas S
2010-10-11 20:00:21 UTC
time = 0; //missing semicolon

clock.start(); //parenthesis required for the method call

int y = 130 - (int)(75 * Math.sin(0.005 * Math.PI * time)); //missing parenthesis before 75

if (y > 130) sky = Color.BLACK; //missing semicolon
Silent
2010-10-11 19:58:26 UTC
If you attempt to compile the code, and there are syntax errors in it, the compiler will tell you exactly where they are and what they are.



That's what those error messages are for. They're not just random strings of text — they tell you what's wrong and how to fix it.



This is a much better way of finding syntax errors than asking random people on the Internet to read the code.
Erika
2016-11-04 10:19:39 UTC
Your software nevertheless isn't doing what you prefer. you should interrupt out of your loop as quickly as this is set that a extensive kind isn't top, and you shouldn't exhibit top extensive kind every time a extensive kind passes the examine. additionally there is not any reason to bypass back the unique extensive kind. If something you should be returning a boolean. this ought to do the trick: deepest static void isPrime(int num1){ int i; boolean isPrime = real; for (i=2; i < num1; i++ ){ if (num1 % i == 0) { isPrime = fake; device.out.println("The extensive kind isn't a main extensive kind!"); wreck; } } if (isPrime) device.out.println("The extensive kind is a main extensive kind!"); }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...