• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

我在代码导致错误的公式是为赋值把出的公式

用户头像
it1352
帮助1

问题说明

//我收到的错误消息是找不到符号方法第二(双)" 但我感觉好像我已经确定了一切. (我显然错了).我认为公式也有问题,但这就是我为公式提供的代码.任何帮助将不胜感激.

//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);
        }
    }

正确答案

#1

这可能不是您想要的:

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

Java将把second当作方法调用,因为它紧随其后的是一个开放式括号,其中有一些值.由于该功能不存在,因此Java会产生该编译错误.

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))

现在我有一点时间来研究它,这些陈述也没有意义:

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));

假设对cos的调用是有效的,则secondHandLength在任何地方都没有定义.此外,您会将计算结果放在地板上,这不是您可能打算做的.我不确定它们的合理值,因为它们似乎与圆的余弦无关,但是需要定义这些变量.

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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfkbbf
系列文章
更多 icon
同类精品
更多 icon
继续加载