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
  • 相关阅读:
    Common Words
    The end of other
    避免ssh断开导致运行命令的终止:screen
    Check iO:初学Python
    linux环境c++开发:ubuntu12.04使用llvm3.4.2
    boost库使用:仿SGI-STL实现的一个树节点allocator
    boost库使用:vs2013下boost::container::vector编译出错解决
    读论文系列:Nearest Keyword Search in XML Documents中使用的数据结构(CT、ECT)
    房产律师咨询
    E文阅读
  • 原文地址:https://www.cnblogs.com/cheese320/p/11355720.html
Copyright © 2011-2022 走看看