<html>
<head>
<title>期末2</title>
</head>
<body>
<script>
var balls = new Array(10);
var i=0,j=0,k=0;
for(i=0;i<10;i++)
{
balls[i]=i+1;
}
for(i=1;i<=1000;i++)
{
j=Math.floor(Math.random()*9);
k=Math.floor(Math.random()*9);
balls[49]=balls[j];
balls[j]=balls[k];
balls[k]=balls[49];
}
document.write(balls[0]+","+balls[1]+","+balls[2]);
</script>
</body>
</html>
物件導向設計
2016年6月3日 星期五
2016年5月20日 星期五
亂數圓餅圖 5.20
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
var a,b,c;
var n1,n2,n3,n4;
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function Ran(){
n1 = 0;
n2 = 0;
n3 = 0;
n4 = 0;
var maxNum = 10;
var minNum = 0;
n1 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
n2 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
n3 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
n4 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
drawChart();
}
function add() {
a=0;
b=0;
c=0;
var radio1 = document.getElementsByName("v1");
var radio2 = document.getElementsByName("v2");
var radio3 = document.getElementsByName("v3");
for(var i=0;i<radio1.length;i++)
{
if(radio1.item(i).checked==true)
{
i = i+1
alert(i);
if (i==1)
{
a=a+1;
}
if (i==2)
{
b=b+1;
}
if (i==3)
{
c=c+1;
}
}}
for(var i=0;i<radio2.length;i++)
{
if(radio2.item(i).checked==true)
{
i = i+1
alert(i);
if (i==1)
{
a=a+1;
}
if (i==2)
{
b=b+1;
}
if (i==3)
{
c=c+1;
}
}}
for(var i=0;i<radio3.length;i++)
{
if(radio3.item(i).checked==true)
{
i = i+1
alert(i);
if (i==1)
{
a=a+1;
}
if (i==2)
{
b=b+1;
}
if (i==3)
{
c=c+1;
}
}}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
drawChart();
}
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['A', n1],
['B', n2],
['C', n3],
['D', n4],
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<h1>你選了什麼?</h1>
<input name="v1" type="radio" value="300年>300年
<input name="v1" type="radio" value="400年>400年
<input name="v1" type="radio" value="1000年>1000年
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="300年>300年
<input name="v2" type="radio" value="400年>400年
<input name="v2" type="radio" value="1000年>1000年
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="300年>300
<input name="v3" type="radio" value="400年>400年
<input name="v3" type="radio" value="1000年>1000年
<br>
Section1:
<input type="text" name="FirstName" id="c1" <br><br/>
Section2:
<input type="text" name="address" id="c2" <br></br>
Section3:
<input type="text" name="address" id="c3" <br></br>
<input type="button" value="submit" onclick="add()"/>
<input type="button" value="Randon" onclick="Ran()"/>
<div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
var a,b,c;
var n1,n2,n3,n4;
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function Ran(){
n1 = 0;
n2 = 0;
n3 = 0;
n4 = 0;
var maxNum = 10;
var minNum = 0;
n1 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
n2 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
n3 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
n4 = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
drawChart();
}
function add() {
a=0;
b=0;
c=0;
var radio1 = document.getElementsByName("v1");
var radio2 = document.getElementsByName("v2");
var radio3 = document.getElementsByName("v3");
for(var i=0;i<radio1.length;i++)
{
if(radio1.item(i).checked==true)
{
i = i+1
alert(i);
if (i==1)
{
a=a+1;
}
if (i==2)
{
b=b+1;
}
if (i==3)
{
c=c+1;
}
}}
for(var i=0;i<radio2.length;i++)
{
if(radio2.item(i).checked==true)
{
i = i+1
alert(i);
if (i==1)
{
a=a+1;
}
if (i==2)
{
b=b+1;
}
if (i==3)
{
c=c+1;
}
}}
for(var i=0;i<radio3.length;i++)
{
if(radio3.item(i).checked==true)
{
i = i+1
alert(i);
if (i==1)
{
a=a+1;
}
if (i==2)
{
b=b+1;
}
if (i==3)
{
c=c+1;
}
}}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
drawChart();
}
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['A', n1],
['B', n2],
['C', n3],
['D', n4],
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<h1>你選了什麼?</h1>
<input name="v1" type="radio" value="300年>300年
<input name="v1" type="radio" value="400年>400年
<input name="v1" type="radio" value="1000年>1000年
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="300年>300年
<input name="v2" type="radio" value="400年>400年
<input name="v2" type="radio" value="1000年>1000年
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="300年>300
<input name="v3" type="radio" value="400年>400年
<input name="v3" type="radio" value="1000年>1000年
<br>
Section1:
<input type="text" name="FirstName" id="c1" <br><br/>
Section2:
<input type="text" name="address" id="c2" <br></br>
Section3:
<input type="text" name="address" id="c3" <br></br>
<input type="button" value="submit" onclick="add()"/>
<input type="button" value="Randon" onclick="Ran()"/>
<div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>
2016年5月6日 星期五
php 在線問卷調查程序
<html>
<head>
<title>Form</title>
<script>
function check1(){
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
for(var i=0;i<radio1.length;i++){
if(radio1.item(i).checked==true){
var flag1 = radio1.item(i).value;
}
}
for(var j=0;j<radio2.length;j++){
if(radio2.item(j).checked==true){
var flag2 = radio2.item(j).value;
}
}
document.write("1、"+flag1+"2、"+flag2);
}
</script>
</head>
<body>
<form action="post.php" method="post" name="add" enctype="multipart/form-data" onSubmit="return check();" >
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="A">A
<input name="v1" type="radio" value="B">B
<input name="v1" type="radio" value="C">C
</form>
<form action="post.php" method="post" name="add" enctype="multipart/form-data" onSubmit="return check();" >
<h1>2、WWWW?</h1>
<input name="v2" type="radio" value="A">A
<input name="v2" type="radio" value="B">B
<input name="v2" type="radio" value="C">C
<input type="button" value="submit" onclick="check1()"/>
</form>
</body>
</html>
<head>
<title>Form</title>
<script>
function check1(){
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
for(var i=0;i<radio1.length;i++){
if(radio1.item(i).checked==true){
var flag1 = radio1.item(i).value;
}
}
for(var j=0;j<radio2.length;j++){
if(radio2.item(j).checked==true){
var flag2 = radio2.item(j).value;
}
}
document.write("1、"+flag1+"2、"+flag2);
}
</script>
</head>
<body>
<form action="post.php" method="post" name="add" enctype="multipart/form-data" onSubmit="return check();" >
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="A">A
<input name="v1" type="radio" value="B">B
<input name="v1" type="radio" value="C">C
</form>
<form action="post.php" method="post" name="add" enctype="multipart/form-data" onSubmit="return check();" >
<h1>2、WWWW?</h1>
<input name="v2" type="radio" value="A">A
<input name="v2" type="radio" value="B">B
<input name="v2" type="radio" value="C">C
<input type="button" value="submit" onclick="check1()"/>
</form>
</body>
</html>
2016年4月22日 星期五
4.22 課堂作業
摻考網址:http://pclevin.blogspot.tw/2014/12/android-studio.html
<resources> <string name="app_name">HelloWorldTest</string> <string name="action_settings">Settings</string> </resources>
2016年4月15日 星期五
eclipse連接到mysql
摻考網址:
http://blog.yslifes.com/archives/918
package db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class jdbcmysql {
private Connection con = null; //Database objects
//連接object
private Statement stat = null;
//執行,傳入之sql為完整字串
private ResultSet rs = null;
//結果集
private PreparedStatement pst = null;
//執行,傳入之sql為預儲之字申,需要傳入變數之位置
//先利用?來做標示
private String dropdbSQL = "DROP TABLE User ";
private String createdbSQL = "CREATE TABLE User (" +
" id INTEGER " +
" , name VARCHAR(20) " +
" , passwd VARCHAR(20))";
private String insertdbSQL = "insert into User(id,name,passwd) " +
"select ifNULL(max(id),0)+1,?,? FROM User";
private String selectSQL = "select * from User ";
public jdbcmysql()
{
try {
Class.forName("com.mysql.jdbc.Driver");
//註冊driver
con = DriverManager.getConnection(
"jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5",
"","");
//取得connection
//jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5
//localhost是主機名,test是database名
//useUnicode=true&characterEncoding=Big5使用的編碼
}
catch(ClassNotFoundException e)
{
System.out.println("DriverClassNotFound :"+e.toString());
}//有可能會產生sqlexception
catch(SQLException x) {
System.out.println("Exception :"+x.toString());
}
}
//建立table的方式
//可以看看Statement的使用方式
public void createTable()
{
try
{
stat = con.createStatement();
stat.executeUpdate(createdbSQL);
}
catch(SQLException e)
{
System.out.println("CreateDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//新增資料
//可以看看PrepareStatement的使用方式
public void insertTable( String name,String passwd)
{
try
{
pst = con.prepareStatement(insertdbSQL);
pst.setString(1, name);
pst.setString(2, passwd);
pst.executeUpdate();
}
catch(SQLException e)
{
System.out.println("InsertDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//刪除Table,
//跟建立table很像
public void dropTable()
{
try
{
stat = con.createStatement();
stat.executeUpdate(dropdbSQL);
}
catch(SQLException e)
{
System.out.println("DropDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//查詢資料
//可以看看回傳結果集及取得資料方式
public void SelectTable()
{
try
{
stat = con.createStatement();
rs = stat.executeQuery(selectSQL);
System.out.println("ID\t\tName\t\tPASSWORD");
while(rs.next())
{
System.out.println(rs.getInt("id")+"\t\t"+
rs.getString("name")+"\t\t"+rs.getString("passwd"));
}
}
catch(SQLException e)
{
System.out.println("DropDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//完整使用完資料庫後,記得要關閉所有Object
//否則在等待Timeout時,可能會有Connection poor的狀況
private void Close()
{
try
{
if(rs!=null)
{
rs.close();
rs = null;
}
if(stat!=null)
{
stat.close();
stat = null;
}
if(pst!=null)
{
pst.close();
pst = null;
}
}
catch(SQLException e)
{
System.out.println("Close Exception :" + e.toString());
}
}
public static void main(String[] args)
{
//測看看是否正常
jdbcmysql test = new jdbcmysql();
test.dropTable();
test.createTable();
test.insertTable("yku", "12356");
test.insertTable("yku2", "7890");
test.SelectTable();
}
http://blog.yslifes.com/archives/918
package db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class jdbcmysql {
private Connection con = null; //Database objects
//連接object
private Statement stat = null;
//執行,傳入之sql為完整字串
private ResultSet rs = null;
//結果集
private PreparedStatement pst = null;
//執行,傳入之sql為預儲之字申,需要傳入變數之位置
//先利用?來做標示
private String dropdbSQL = "DROP TABLE User ";
private String createdbSQL = "CREATE TABLE User (" +
" id INTEGER " +
" , name VARCHAR(20) " +
" , passwd VARCHAR(20))";
private String insertdbSQL = "insert into User(id,name,passwd) " +
"select ifNULL(max(id),0)+1,?,? FROM User";
private String selectSQL = "select * from User ";
public jdbcmysql()
{
try {
Class.forName("com.mysql.jdbc.Driver");
//註冊driver
con = DriverManager.getConnection(
"jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5",
"","");
//取得connection
//jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=Big5
//localhost是主機名,test是database名
//useUnicode=true&characterEncoding=Big5使用的編碼
}
catch(ClassNotFoundException e)
{
System.out.println("DriverClassNotFound :"+e.toString());
}//有可能會產生sqlexception
catch(SQLException x) {
System.out.println("Exception :"+x.toString());
}
}
//建立table的方式
//可以看看Statement的使用方式
public void createTable()
{
try
{
stat = con.createStatement();
stat.executeUpdate(createdbSQL);
}
catch(SQLException e)
{
System.out.println("CreateDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//新增資料
//可以看看PrepareStatement的使用方式
public void insertTable( String name,String passwd)
{
try
{
pst = con.prepareStatement(insertdbSQL);
pst.setString(1, name);
pst.setString(2, passwd);
pst.executeUpdate();
}
catch(SQLException e)
{
System.out.println("InsertDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//刪除Table,
//跟建立table很像
public void dropTable()
{
try
{
stat = con.createStatement();
stat.executeUpdate(dropdbSQL);
}
catch(SQLException e)
{
System.out.println("DropDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//查詢資料
//可以看看回傳結果集及取得資料方式
public void SelectTable()
{
try
{
stat = con.createStatement();
rs = stat.executeQuery(selectSQL);
System.out.println("ID\t\tName\t\tPASSWORD");
while(rs.next())
{
System.out.println(rs.getInt("id")+"\t\t"+
rs.getString("name")+"\t\t"+rs.getString("passwd"));
}
}
catch(SQLException e)
{
System.out.println("DropDB Exception :" + e.toString());
}
finally
{
Close();
}
}
//完整使用完資料庫後,記得要關閉所有Object
//否則在等待Timeout時,可能會有Connection poor的狀況
private void Close()
{
try
{
if(rs!=null)
{
rs.close();
rs = null;
}
if(stat!=null)
{
stat.close();
stat = null;
}
if(pst!=null)
{
pst.close();
pst = null;
}
}
catch(SQLException e)
{
System.out.println("Close Exception :" + e.toString());
}
}
public static void main(String[] args)
{
//測看看是否正常
jdbcmysql test = new jdbcmysql();
test.dropTable();
test.createTable();
test.insertTable("yku", "12356");
test.insertTable("yku2", "7890");
test.SelectTable();
}
4.15 期中考
package haha;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverManager;
public class haha {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello! World!");
Connection c = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:test.db");
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
// TODO Auto-generated method stub
System.out.println("Hello! World!");
Connection c = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:test.db");
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
}
教學網站:
http://readandplay.pixnet.net/blog/post/140001110-%E7%AC%AC%E4%B8%80%E6%94%AFandroid-app%E7%A8%8B%E5%BC%8F%E6%95%99%E5%AD%B8
訂閱:
文章 (Atom)