Solaris8下编译java demo程序的问题

发布于 2022-10-15 09:22:33 字数 15833 浏览 37 评论 0

Solaris8已经安装了JDK1。3
但是编译其中的一个图形示例程序时出现如下错误提示:

Exdception in thread "main" java.lang.NoSuchMethodError:main
请问如何解决?

  1. /*
  2. * @(#)Clock2.java        1.5 98/07/09
  3. *
  4. * Copyright (c) 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  7. * modify and redistribute this software in source and binary code form,
  8. * provided that i) this copyright notice and license appear on all copies of
  9. * the software; and ii) Licensee does not utilize the software in a manner
  10. * which is disparaging to Sun.
  11. *
  12. * This software is provided "AS IS," without a warranty of any kind. ALL
  13. * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  14. * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  15. * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  16. * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  17. * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  18. * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  19. * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  20. * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  21. * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  22. * POSSIBILITY OF SUCH DAMAGES.
  23. *
  24. * This software is not designed or intended for use in on-line control of
  25. * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  26. * the design, construction, operation or maintenance of any nuclear
  27. * facility. Licensee represents and warrants that it will not use or
  28. * redistribute the Software for such purposes.
  29. */
  30. import java.util.*;
  31. import java.awt.*;
  32. import java.applet.*;
  33. import java.text.*;
  34. /**
  35. * Time!
  36. *
  37. * @author Rachel Gollub
  38. */
  39. public class Clock2 extends Applet implements Runnable {
  40.     Thread timer;                // The thread that displays clock
  41.     int lastxs, lastys, lastxm,
  42.         lastym, lastxh, lastyh;  // Dimensions used to draw hands
  43.     SimpleDateFormat formatter;  // Formats the date displayed
  44.     String lastdate;             // String to hold date displayed
  45.     Font clockFaceFont;          // Font for number display on clock
  46.     Date currentDate;            // Used to get date to display
  47.     Color handColor;             // Color of main hands and dial
  48.     Color numberColor;           // Color of second hand and numbers
  49.     public void init() {
  50.         int x,y;
  51.         lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
  52.         formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());
  53.         currentDate = new Date();
  54.         lastdate = formatter.format(currentDate);
  55.         clockFaceFont = new Font("Serif", Font.PLAIN, 14);
  56.         handColor = Color.blue;
  57.         numberColor = Color.darkGray;
  58.         try {
  59.             setBackground(new Color(Integer.parseInt(getParameter("bgcolor"),16)));
  60.         } catch (Exception E) { }
  61.         try {
  62.             handColor = new Color(Integer.parseInt(getParameter("fgcolor1"),16));
  63.         } catch (Exception E) { }
  64.         try {
  65.             numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"),16));
  66.         } catch (Exception E) { }
  67.         resize(300,300);              // Set clock window size
  68.     }
  69.     // Plotpoints allows calculation to only cover 45 degrees of the circle,
  70.     // and then mirror
  71.     public void plotpoints(int x0, int y0, int x, int y, Graphics g) {
  72.         g.drawLine(x0+x,y0+y,x0+x,y0+y);
  73.         g.drawLine(x0+y,y0+x,x0+y,y0+x);
  74.         g.drawLine(x0+y,y0-x,x0+y,y0-x);
  75.         g.drawLine(x0+x,y0-y,x0+x,y0-y);
  76.         g.drawLine(x0-x,y0-y,x0-x,y0-y);
  77.         g.drawLine(x0-y,y0-x,x0-y,y0-x);
  78.         g.drawLine(x0-y,y0+x,x0-y,y0+x);
  79.         g.drawLine(x0-x,y0+y,x0-x,y0+y);
  80.     }
  81.     // Circle is just Bresenham's algorithm for a scan converted circle
  82.     public void circle(int x0, int y0, int r, Graphics g) {
  83.         int x,y;
  84.         float d;
  85.         x=0;
  86.         y=r;
  87.         d=5/4-r;
  88.         plotpoints(x0,y0,x,y,g);
  89.         while (y>x){
  90.             if (d<0) {
  91.                 d=d+2*x+3;
  92.                 x++;
  93.             }
  94.             else {
  95.                 d=d+2*(x-y)+5;
  96.                 x++;
  97.                 y--;
  98.             }
  99.             plotpoints(x0,y0,x,y,g);
  100.         }
  101.     }
  102.     // Paint is the main part of the program
  103.     public void paint(Graphics g) {
  104.         int xh, yh, xm, ym, xs, ys, s = 0, m = 10, h = 10, xcenter, ycenter;
  105.         String today;
  106.         currentDate = new Date();
  107.         SimpleDateFormat formatter = new SimpleDateFormat("s",Locale.getDefault());
  108.         try {
  109.             s = Integer.parseInt(formatter.format(currentDate));
  110.         } catch (NumberFormatException n) {
  111.             s = 0;
  112.         }
  113.         formatter.applyPattern("m");
  114.         try {
  115.             m = Integer.parseInt(formatter.format(currentDate));
  116.         } catch (NumberFormatException n) {
  117.             m = 10;
  118.         }   
  119.         formatter.applyPattern("h");
  120.         try {
  121.             h = Integer.parseInt(formatter.format(currentDate));
  122.         } catch (NumberFormatException n) {
  123.             h = 10;
  124.         }
  125.         formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
  126.         today = formatter.format(currentDate);
  127.         xcenter=80;
  128.         ycenter=55;
  129.    
  130.     // a= s* pi/2 - pi/2 (to switch 0,0 from 3:00 to 12:00)
  131.     // x = r(cos a) + xcenter, y = r(sin a) + ycenter
  132.    
  133.         xs = (int)(Math.cos(s * 3.14f/30 - 3.14f/2) * 45 + xcenter);
  134.         ys = (int)(Math.sin(s * 3.14f/30 - 3.14f/2) * 45 + ycenter);
  135.         xm = (int)(Math.cos(m * 3.14f/30 - 3.14f/2) * 40 + xcenter);
  136.         ym = (int)(Math.sin(m * 3.14f/30 - 3.14f/2) * 40 + ycenter);
  137.         xh = (int)(Math.cos((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + xcenter);
  138.         yh = (int)(Math.sin((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + ycenter);
  139.    
  140.     // Draw the circle and numbers
  141.    
  142.         g.setFont(clockFaceFont);
  143.         g.setColor(handColor);
  144.         circle(xcenter,ycenter,50,g);
  145.         g.setColor(numberColor);
  146.         g.drawString("9",xcenter-45,ycenter+3);
  147.         g.drawString("3",xcenter+40,ycenter+3);
  148.         g.drawString("12",xcenter-5,ycenter-37);
  149.         g.drawString("6",xcenter-3,ycenter+45);
  150.     // Erase if necessary, and redraw
  151.    
  152.         g.setColor(getBackground());
  153.         if (xs != lastxs || ys != lastys) {
  154.             g.drawLine(xcenter, ycenter, lastxs, lastys);
  155.             g.drawString(lastdate, 5, 125);
  156.         }
  157.         if (xm != lastxm || ym != lastym) {
  158.             g.drawLine(xcenter, ycenter-1, lastxm, lastym);
  159.             g.drawLine(xcenter-1, ycenter, lastxm, lastym); }
  160.         if (xh != lastxh || yh != lastyh) {
  161.             g.drawLine(xcenter, ycenter-1, lastxh, lastyh);
  162.             g.drawLine(xcenter-1, ycenter, lastxh, lastyh); }
  163.         g.setColor(numberColor);
  164.         g.drawString("", 5, 125);
  165.         g.drawString(today, 5, 125);   
  166.         g.drawLine(xcenter, ycenter, xs, ys);
  167.         g.setColor(handColor);
  168.         g.drawLine(xcenter, ycenter-1, xm, ym);
  169.         g.drawLine(xcenter-1, ycenter, xm, ym);
  170.         g.drawLine(xcenter, ycenter-1, xh, yh);
  171.         g.drawLine(xcenter-1, ycenter, xh, yh);
  172.         lastxs=xs; lastys=ys;
  173.         lastxm=xm; lastym=ym;
  174.         lastxh=xh; lastyh=yh;
  175.         lastdate = today;
  176.         currentDate=null;
  177.     }
  178.     public void start() {
  179.         timer = new Thread(this);
  180.         timer.start();
  181.     }
  182.     public void stop() {
  183.         timer = null;
  184.     }
  185.     public void run() {
  186.         Thread me = Thread.currentThread();
  187.         while (timer == me) {
  188.             try {
  189.                 Thread.currentThread().sleep(100);
  190.             } catch (InterruptedException e) {
  191.             }
  192.             repaint();
  193.         }
  194.     }
  195.     public void update(Graphics g) {
  196.         paint(g);
  197.     }
  198.     public String getAppletInfo() {
  199.         return "Title: A Clock \nAuthor: Rachel Gollub, 1995 \nAn analog clock.";
  200.     }
  201.   
  202.     public String[][] getParameterInfo() {
  203.         String[][] info = {
  204.             {"bgcolor", "hexadecimal RGB number", "The background color. Default is the color of your browser."},
  205.             {"fgcolor1", "hexadecimal RGB number", "The color of the hands and dial. Default is blue."},
  206.             {"fgcolor2", "hexadecimal RGB number", "The color of the seconds hand and numbers. Default is dark gray."}
  207.         };
  208.         return info;
  209.     }
  210. }

复制代码

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

π浅易 2022-10-22 09:22:33

你不看提示的么?
Exdception in thread "main" java.lang.NoSuchMethodError:main

没有main方法

酷到爆炸 2022-10-22 09:22:33

我已经手工加入MAIN方法了,编译通过,但是执行时候什么都出不来,是空的

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文