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);
}
}
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的更多相关文章
- 【译】快速高效学习Java编程在线资源Top 20
想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...
- 快速高效学习Java编程在线资源Top 20(转载)
想要加强你的编程能力吗?想要提升你的 Java 编程技巧和效率吗? 不用担心.本文将会提供快速高效学习 Java 编程的 50 多个网站资源: 开始探索吧: 1.MKyong:许多开发者在这里可以找到 ...
随机推荐
- Multi-Agent Reinforcement Learning Based Frame Sampling for Effective Untrimmed Video Recognition
Multi-Agent Reinforcement Learning Based Frame Sampling for Effective Untrimmed Video Recognition IC ...
- https://www.cnblogs.com/LBSer/p/3310455.html
https://www.cnblogs.com/LBSer/p/3310455.html
- 使用spring validation完成数据后端校验-自定义校验的注解-判断是否为空
引入依赖 我们使用maven构建springboot应用来进行demo演示. <dependencies> <dependency> <groupId>org.sp ...
- C#使用SHA1加密类(RSAFromPkcs8)支持1024位和2048位私钥
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- vi中使用删除键(backspace)只能删除到行首不能跳到上一行怎么处理?
答: 在~/.vimrc中加入以下内容: set backspace=2
- Hive Authorization
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Authorization https://www.cloudera.c ...
- Angularjs Select获取数组下标
一.定义资源 //资源类型 $scope.status=['项目测试','开发工具','安装包','工作计划','测试项目','我的游戏','我的音乐','博客首页图片']; 二.没错直接用 {{$ ...
- 一文读懂ZooKeeper (转)
什么是ZooKeeper ZooKeeper 是一个分布式的,开放源码的分布式应用程序协同服务.ZooKeeper 的设计目标是将那些复杂且容易出错的分布式一致性服务封装起来,构成一个高效可靠的原语集 ...
- IP通信学习心得02
1.7层模型 2.OSI的应用 3.如何辨别.数清冲突域和广播域 1)首先,须知第一层不能隔离冲突域和广播域.例如集线器或者直接连PC 2)其次,第二层可以隔离冲突域,但不能隔离广播域.例如,二层交换 ...
- 谈谈php里的IOC控制反转,DI依赖注入(转)
转自:http://www.cnblogs.com/qq120848369/p/6129483.html 发现问题 在深入细节之前,需要确保我们理解"IOC控制反转"和" ...