Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

java - The formula that I have in my code which is causing the error is the formula that was given for the assignment

//The error message I'm getting is saying "cannot find symbol- method second(double) but I feel as though I have identified everything already. (I'm clearly wrong). I think there is a problem with the formula as well but that is the code I was given for the formula. Any help would be greatly appreciated.

    import java.util.GregorianCalendar;
    import javax.swing.JComponent;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import java.awt.*;//import * Class

    public class ClockComponent extends JComponent
    {

        double hour;
        double minute;
        double second;

        public void setCurrentTime()
        { 

            GregorianCalendar calendar = new GregorianCalendar(); 


            hour = calendar.get(calendar.HOUR_OF_DAY);
            minute = calendar.get(calendar.MINUTE);
            second = calendar.get(calendar.SECOND);
        }   

        public void paintComponent(Graphics g)
        {
            Graphics2D g2 = (Graphics2D) g;

            int xCoord = 40;
            int yCoord = 25;



            Ellipse2D.Double clockFace = new Ellipse2D.Double(xCoord, yCoord, 700, 700);      
            g2.setColor(Color.black);
            g2.draw(clockFace);
            g2.fill(clockFace);



            g2.setColor(Color.red);
            Font font1 = new Font("Old English Text MT",Font.BOLD,30);
            g2.setFont(font1);
            g2.drawString("John Doe", 305, 680);



            g2.setColor(Color.yellow);
            Font font2 = new Font("Arial",Font.BOLD,30);
            g2.setFont(font2);
            g2.drawString("III", xCoord + 670, yCoord + 355);
            g2.drawString("VI", xCoord + 340, yCoord + 685);
            g2.drawString("IX", xCoord + 10, yCoord + 355);
            g2.drawString("XII", xCoord + 340, yCoord + 35);



            int xCenter = 380;
            int yCenter = 380;

            double secondHandLength;
            double minuteHandLength;
            double hourHandLength;

            double xSecond = xCenter + secondHandLength; cos(second (2*Math.PI/60));
            double ySecond = yCenter - secondHandLength; sin(second (2*Math.PI/60)); 

            double xMinute = xCenter + minuteHandLength; cos(2*Math.PI/60);
            double yMinute = yCenter - minuteHandLength; sin(2*Math.PI/60);

            double xHour = xCenter + hourHandLength; cos(2*Math.PI/60);
            double yHour = yCenter - hourHandLength; sin(2*Math.PI/60);



            g2.setColor(Color.blue);
            Line2D.Double secHand = new Line2D.Double(xCenter,yCenter,xSecond,ySecond);
            g2.setStroke(new BasicStroke(1));
            g2.draw(secHand);


            Line2D.Double minHand = new Line2D.Double(xCenter,yCenter,xMinute,yMinute);
            g2.setStroke(new BasicStroke(7));
            g2.draw(minHand);


            Line2D.Double hourHand = new Line2D.Double(xCenter,yCenter,xHour,yHour);
            g2.setStroke(new BasicStroke(13));
            g2.draw(hourHand);
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This probably isn't what you want:

(second (2*Math.PI/60))

Java is going to treat second as a method call, as it is immediately followed by an open-paren, with some value in it. Since that function doesn't exist, Java produces that compilation error.

If you were trying to get the product of the two, you have to explicitly provide the multiplication operator.

(second * (2*Math.PI/60))

EDIT: Now that I've had a moment to look at it, these statements also don't make sense:

double xSecond = xCenter + secondHandLength; cos(second (2*Math.PI/60));

Assuming the call to cos was valid, secondHandLength isn't defined anywhere. What's more, you're dropping the result of your calculation on the floor, which isn't what you likely intend to do. I'm not sure what a sane value would be for them, since they seem independent of the cosine of a circle, but those variables need to be defined.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...