<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
<Script type ="text/javascript">
var rx, rx1, rx2, maxNum, minNum;
minNum=0;
maxNum=9;
rx=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
rx1=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
rx2=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
while(rx1==rx || rx1==rx2){
rx1=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
}
while(rx2==rx || rx2==rx1){
rx2=Math.floor( Math.random() * (maxNum - minNum + 1) ) + minNum;
}
document.write("亂數"+rx+rx1+rx2);
</Script>
</body>
</html>
JAVA程式設計工藝大師
2016年6月2日 星期四
加法運算器
<!DOCTYPE html >
<html >
<head>
<title>加法運算器</title>
<head>
<title>加法運算器</title>
<script>
function add() {
var a = parseInt(document.getElementById('a').value);
var b = parseInt(document.getElementById('b').value);
document.getElementById('result').value = a+b ;
}
</script>
</head>
<body>
<input id="a" type="text" />+<input id="b" type="text" />
<button onclick="add()">=</button>
<output id="result"></output>
</body>
</html>
<html >
<head>
<title>加法運算器</title>
<head>
<title>加法運算器</title>
<script>
function add() {
var a = parseInt(document.getElementById('a').value);
var b = parseInt(document.getElementById('b').value);
document.getElementById('result').value = a+b ;
}
</script>
</head>
<body>
<input id="a" type="text" />+<input id="b" type="text" />
<button onclick="add()">=</button>
<output id="result"></output>
</body>
</html>
2016年5月20日 星期五
亂數圓餅變化圖
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
var a,b,c;
a=0;
b=0;
c=0;
var n1=0;
var n2=0;
var n3=0;
var n4=0;
function Random() {
var maxNum = 4;
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() {
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;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
break;
}
}
drawChart();
}
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['AAA', n1],
['BBB', n2],
['CCC', n3],
['DDD', 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="AAA">AAA
<input name="v1" type="radio" value="BBB">BBB
<input name="v1" type="radio" value="CCC">CCC
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="AAA">AAA
<input name="v2" type="radio" value="BBB">BBB
<input name="v2" type="radio" value="CCC">CCC
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="AAA">AAA
<input name="v3" type="radio" value="BBB">BBB
<input name="v3" type="radio" value="CCC">CCC
<br>
c1:
<input type="text" name="FirstName" id="c1" <br><br/>
c2:
<input type="text" name="address" id="c2" <br></br>
c3:
<input type="text" name="address" id="c3" <br></br>
<input type="button" value="submit" onclick="add()"/>
<input type="button" value="random" onclick="Random()"/>
<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">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
var a,b,c;
a=0;
b=0;
c=0;
var n1=0;
var n2=0;
var n3=0;
var n4=0;
function Random() {
var maxNum = 4;
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() {
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;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
break;
}
}
drawChart();
}
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['AAA', n1],
['BBB', n2],
['CCC', n3],
['DDD', 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="AAA">AAA
<input name="v1" type="radio" value="BBB">BBB
<input name="v1" type="radio" value="CCC">CCC
<br>
<h1>你選了什麼?</h1>
<input name="v2" type="radio" value="AAA">AAA
<input name="v2" type="radio" value="BBB">BBB
<input name="v2" type="radio" value="CCC">CCC
<br>
<h1>你選了什麼?</h1>
<input name="v3" type="radio" value="AAA">AAA
<input name="v3" type="radio" value="BBB">BBB
<input name="v3" type="radio" value="CCC">CCC
<br>
c1:
<input type="text" name="FirstName" id="c1" <br><br/>
c2:
<input type="text" name="address" id="c2" <br></br>
c3:
<input type="text" name="address" id="c3" <br></br>
<input type="button" value="submit" onclick="add()"/>
<input type="button" value="random" onclick="Random()"/>
<div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>
2016年5月13日 星期五
選擇題圓餅圖
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
var a ;
var b ;
var c ;
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;
}
else
if(i==2){
b=b+1;
}
else{
c=c+1;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
}
else
if(i==2){
b=b+1;
}
else{
c=c+1;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
}
else
if(i==2){
b=b+1;
}
else{
c=c+1;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
drawChart();
}
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', a],
['Eat', b],
['Commute', c],
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="1.1">300年
<input name="v1" type="radio" value="1.2">400年
<input name="v1" type="radio" value="1.3">1000年
<br>
<h1>2、ssss?</h1>
<input name="v2" type="radio" value="1.1">300年
<input name="v2" type="radio" value="1.2">400年
<input name="v2" type="radio" value="1.3">1000年
<br>
<h1>3、ssss?</h1>
<input name="v3" type="radio" value="1.1">300年
<input name="v3" type="radio" value="1.2">400年
<input name="v3" type="radio" value="1.3">1000年
<br>
c1:
<input type="text" name="FirstName" id="c1"<br><br/>
c2:
<input type="text" name="address" id="c2"<br><br/>
c3:
<input type="text" name="qwe" id="c3"<br><br/>
<input type="button" value="submit" onclick="add()"/>
<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">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
var a ;
var b ;
var c ;
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;
}
else
if(i==2){
b=b+1;
}
else{
c=c+1;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
}
else
if(i==2){
b=b+1;
}
else{
c=c+1;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
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;
}
else
if(i==2){
b=b+1;
}
else{
c=c+1;
}
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
break;
}
}
drawChart();
}
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', a],
['Eat', b],
['Commute', c],
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="1.1">300年
<input name="v1" type="radio" value="1.2">400年
<input name="v1" type="radio" value="1.3">1000年
<br>
<h1>2、ssss?</h1>
<input name="v2" type="radio" value="1.1">300年
<input name="v2" type="radio" value="1.2">400年
<input name="v2" type="radio" value="1.3">1000年
<br>
<h1>3、ssss?</h1>
<input name="v3" type="radio" value="1.1">300年
<input name="v3" type="radio" value="1.2">400年
<input name="v3" type="radio" value="1.3">1000年
<br>
c1:
<input type="text" name="FirstName" id="c1"<br><br/>
c2:
<input type="text" name="address" id="c2"<br><br/>
c3:
<input type="text" name="qwe" id="c3"<br><br/>
<input type="button" value="submit" onclick="add()"/>
<div id="piechart" style="width: 900px; height: 500px;"></div>
</body>
</html>
2016年4月21日 星期四
建立資料庫and把資料顯示在網頁上
http://localhost/phpmyadmin進入資料庫
建立資料表
按新增 把資料打進去
資料就建好了
接下來把資料顯示在網頁上
創一個文字檔 把檔名改成xxx.php
放到對的位置
程式碼
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `user`";
$result = $conn->query($sql);
if ($result != null) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["name"]. $row["passwd"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
然後就
接下來把資料顯示在網頁上
創一個文字檔 把檔名改成xxx.php
放到對的位置
程式碼
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `user`";
$result = $conn->query($sql);
if ($result != null) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["name"]. $row["passwd"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
然後就
第一個APP 計算BMI
http://appinventor.mit.edu/explore/content/windows.html
My Projects頁面建立一個專案
開始做BMI APP
然後 build ---> app ---> 掃描QRcode即可
My Projects頁面建立一個專案
開始做BMI APP
然後 build ---> app ---> 掃描QRcode即可
Eclipse連接MySQL資料庫
下載Eclipse
1.在Eclipse建立一個專案增加一個Class
二.設定class name跟package name
三.載入JDBC-Drive
四.程式碼
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();
}
}
五.執行ok即可
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();
}
}
五.執行ok即可
訂閱:
文章 (Atom)