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

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

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

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

Programmingbydoing的更多相关文章

  1. 【译】快速高效学习Java编程在线资源Top 20

    想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...

  2. 快速高效学习Java编程在线资源Top 20(转载)

    想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...

随机推荐

  1. ls列出排除的文件

    今天有个需求,将从日志文件夹中列出它排除旧备份日志的文件. ls -lhrt --ignore="*.gz" --ignore="*.zip"

  2. android -------- SHA 加密算法

    安全散列算法(英语:Secure Hash Algorithm,缩写为SHA)是一个密码散列函数家族,是FIPS所认证的安全散列算法.能计算出一个数字消息所对应到的,长度固定的字符串(又称消息摘要)的 ...

  3. 使用create-react-app遇到问题解决方案汇总

    使用create-react-app时遇到Module not found问题 转 https://blog.csdn.net/wkq_1212/article/details/90291558 本来 ...

  4. C# winform判断窗体是否已打开

    Form1 form; /// <summary> /// 开始检测 /// </summary> /// <param name="sender"& ...

  5. BIM数据格式中IFC的标准及格式

    传统工程数据往往零散且片段的储存在各个不同的地方,数据格式也有各种不同的形式互相搭配,最常见的有图形(施工图.大样图.断面图.流程图等).文字(各种说明文件).数字(各种统计.数量或价格数据),这些数 ...

  6. Javascript-基本使用

    本章向您提供了展示 JavaScript 能力的部分实例. JavaScript 能够改变 HTML 内容 getElementById() 是多个 JavaScript HTML 方法之一. 本例使 ...

  7. jQuery fancy box 移除close "X" button

    version: fancybox 2.1.4 <div id="reloadPagePopup" class="div-fancy-box"> & ...

  8. [LeetCode] 202. Happy Number 快乐数

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

  9. SecureCRT 使用密钥登录 Ubuntu

    记录 SecureCRT 通过 SSH 使用密钥登录 Ubuntu. 具体步骤如下: 1. 使用 SecureCRT 生成密钥对: 工具 -> 创建公钥 -> 密钥类型 RSA -> ...

  10. Java基础之(四)HashMap(jdk10)

    JDK1.7以前的HashMap jdk1.7中,当冲突时,在冲突的地址上生成一个链表,将冲突的元素的key,通过equals进行比较,相同即覆盖,不同则添加到链表上,此时如果链表过长,效率就会大大降 ...