当前位置: 代码迷 >> Java相关 >> 关于图的输出问题
  详细解决方案

关于图的输出问题

热度:99   发布时间:2011-10-16 10:12:38.0
关于图的输出问题
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class experiment_5_23 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub


        final double PI=3.1415926;
        int hour,minute,str=1;
        double hu_hour;
        double hu_Minute;;
        Scanner scanner=new Scanner(System.in);
        do{
            System.out.println("请输入多少点:(0~12):");
            hour=scanner.nextInt();
        }while(hour<0||hour>12);
        
        do{
            System.out.println("请输入多少分钟(0~59):");
            minute=scanner.nextInt();
        }while(minute<0||minute>59);
        
        JFrame win;
        Container contentPane;
        Graphics g;
        
        win=new JFrame("My frist Rectangle");
        win.setSize(300,300);
        win.setLocation(100, 100);
        win.setVisible(true);

        
        contentPane=win.getContentPane();
        g=contentPane.getGraphics();
        
        while(str<100)
        {
            str++;
        g.drawOval(50, 50, 200, 200);
        Point pt=new Point();
        pt.x=150;
        pt.y=150;
        
        g.drawString("12",145,65);
        g.drawString("3",240,150);
        g.drawString("6",150,245);
        g.drawString("9",52,150);
        
        hu_Minute=(double)minute*2*PI/60;
        hu_hour=(hour+(double)minute/60)*2*PI/12;
        g.drawLine(150, 150, (int)(150+75*Math.sin(hu_Minute)), (int)(150-75*Math.cos(hu_Minute)));
        g.drawLine(150, 150, (int)(150+60*Math.sin(hu_hour)), (int)(150-60*Math.cos(hu_hour)));
        
        }
   
    }

}



在我电脑上测试,当str<35时,所画的图一闪而过,当str>35时。图就显示出来,当切换窗口时,图就会不见了。这是不是与系统的刷新周期或软件本身原因。望多位多多帮忙~~~~
搜索更多相关的解决方案: public  double  import  method  minute  

----------------解决方案--------------------------------------------------------
  相关解决方案