zoukankan      html  css  js  c++  java
  • Programmingbydoing

    http://www.programmingbydoing.com/

    1. Modulus Animation

     public static void modulusAnimation() throws InterruptedException {
            int repeats = 5;
            int steps_per_seconds = 10;
            for(int i=0; i<repeats*11; i++){
                if(i%11==0){
                    System.out.println(",oOo.....");
                } else if (i%11==1){
                    System.out.println("..oOo....");
                }else if (i%11==2){
                    System.out.println("...oOo...");
                }else if (i%11==3){
                    System.out.println("....oOo..");
                }else if (i%11==4){
                    System.out.println(".....oOo.");
                }else if (i%11==5){
                    System.out.println("......oOo");
                }else if (i%11==6){
                    System.out.println(".........oO");
                }else if (i%11==7){
                    System.out.println("o.......o");
                }else if (i%11==8){
                    System.out.println("Oo.......");
                }else if (i%11==9){
                    System.out.println("oOo......");
                }else if (i%11==10){
                    System.out.println(".oOo.....");
                }else if (i%11==11){
                    System.out.println("..oOo....");
                }
                
                Thread.sleep(1000/steps_per_seconds);
            }
        }
    View Code

    2.Using swing for input

     public static void inputBox(){
            String name = JOptionPane.showInputDialog("What's your name?");
            String input = JOptionPane.showInputDialog("How old are you");
            int age = Integer.parseInt(input);
    
            System.out.println("Hello, " + name);
            System.out.println("Next year, you will be " + (age+1));
            System.exit(0);
        }
    View Code

    3. A frame with a Panel with writing on it

    import javax.swing.*;
    import java.awt.*;
    
    
    public class Prog613 {
        public static void main(String[] args) {
            Frame613 f = new Frame613();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setVisible(true);
        }
    }
    
    class Frame613 extends JFrame {
        public Frame613(){
            setTitle("613 rocks");
            setSize(300,200);
            setLocation(100,200);
            
            Panel613 panel = new Panel613();
            Container cp = getContentPane();
            cp.add(panel);
        }
    }
    
    class Panel613 extends JPanel{ 
        public void paintComponent(Graphics g){
            super.paintComponent(g);
            g.drawString("Hi, ",75, 100);
        }
        
    }
    View Code

    4. Graphics Demo1

    import javax.swing.*;
    import java.awt.*;
    
    public class GraphicsDemo1 extends Canvas {
        public static void main(String[] args) {
            JFrame win = new JFrame("GraphicsDemo1");
            win.setSize(600,800);
            win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            GraphicsDemo1 canvas = new GraphicsDemo1();
            win.add(canvas);
            win.setVisible(true);
        }
        
        
        public void paint(Graphics g){
            g.setColor(Color.green);
            g.drawRect(50,20,100,200);
            g.fillOval(160,20,100,200);
            g.setColor(Color.blue);
            g.fillRect(200,400,200,20);
            g.drawOval(200,430,200,100);
            
            
            g.setColor(Color.black);
            g.drawString("Graphics are pretty neat. ",500,100);
            int x = getWidth()/2;
            int y = getHeight()/2;
            g.drawString("The first letter of this string is at (" + x + ","+y+")",x,y);
            
        }
        
    }
    View Code
  • 相关阅读:
    人与人之间的本质
    如何让百度搜索不到
    js.prototype最深刻的理解
    调用函数不能用&
    浏览器的缓存就是关闭了浏览器任然存在
    Spring switch的使用
    thymeleaf如何遍历数据 each循环的使用
    spring 机制 扫描包
    Spring分层次建包
    如何使用thymeleaf显示控制传递过来的数据
  • 原文地址:https://www.cnblogs.com/cheese320/p/11355720.html
Copyright © 2011-2022 走看看