21 ก.ค. 2554

Test

public class Find {
 public static void main(String args[]){
        System.out.println("Hello Terry");
 }
}

http://www.helloandroid.com/tutorials/how-download-fileimage-url-your-device

http://intereladsd.blogspot.com/

http://www.java-samples.com/showtutorial.php?tutorialid=152

http://www.4shared.com/file/s3XN43BY/Invoke.html

ภาษา script และภาษาโปรแกรมทั่วไป

ถ้าพูดถึงภาษา script นั้นเป็นภาษาที่มีหลักการแบบ แทรกเข้าไปมาภาษาอื่น ทำให้สามารถทำงานต่างๆได้มากขี้น โดย sintag นั้นจะมีความกระชับเข้าใจง่าย โดยเฉพาะ เรื่องตัวแปรนั้นจะยืดหยุ่นมาก จะประกาศตัวแปรแบบไหนก็ได้ โดยที่ script นั้นจะเป็นตัวแปรให้เราเองโดยอัตโนมัติ มีการใช้ภาษา script ในการทำงานต่างๆเช่น การทำเว็บไชต์ จะทำการแทรก script เข้าไปเพื่อให้ browser นั้นทำงานได้หลากหลายมากยิ่งขึ้น เช่น php ,javascript ,perl,python,ajax,flash ภาษาเหล่านี้ จะมีการทำงานเชื่อมต่อกันได้กับภาษาอื่นๆ
ส่วนภาษาอื่นนั้นก็จะเน้นด้านการวางโครงสร้างของโปรแกรม เป็นการสร้างโปรแกรมที่จะมีส่วนประกอบที่เยอะมากขึ้นเน้นความมีเสถียรภาพด้าน กระบวนการ ในปัจจุบัน ภาษา script มีบทบาท มากขึ้น ในการทำเว็บไชต์ เมื่อสมัยก่อนหลักการเริ่มแรกของเว็บคือสามารถส่งผ่านข้อมูลได้ทุกแพลตฟอร์ม ไม้ว่าเปิดที่ไหนก็อ่านได้ แต่ในทุกวันนี้มี สิ่งต่างๆมากมาย ที่ทำให้เว็บไชต์พัฒนาขึ้น เพราะ เป็นสิ่งที่เชื่อมต่อกับคนทั่วโลกได้
Published with Blogger-droid v1.7.4

19 ก.ค. 2554

Xml to Html

แปลง  xml เป็น html

ไฟล์ hello.xsl

<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="h1">
       <h1>
      <center>
     <xsl:value-of select="."/>
               </center>
            </h1>
</xsl:template>
<xsl:template match="bold">
     <table align="center" border="1">
       <tr>
    <xsl:for-each select=".">
       <td>
        <xsl:value-of select="."/>
       </td>
    </xsl:for-each>
            </tr>
     </table>
</xsl:template>
<xsl:template match="red">
<table align="center" border="1">
      <tr>
   <td>
     <p style="color:red">
    <xsl:value-of select="."/>
     </p>
   </td>
        </tr>  
     </table>
</xsl:template>
<xsl:template match="italic">
<table align="center" border="1">
      <tr>
   <td>
    <p>
     <xsl:value-of select="."/>
    </p>
            </td>
        </tr>
          
     </table>
</xsl:template>
</xsl:stylesheet> 

hello.xml


<?xml version="1.0"?>

<source>

<h1>TEST XSLT FOR CREATE WEB SITE BY WONGSAKORN</h1>

<bold>Hello1, world.</bold>

<bold>Hello2, world.</bold>

<bold>Hello3, world.</bold>

<bold>Hello4, world.</bold>

<bold>Hello5, world.</bold>

<red>I am </red>

<italic>fine.</italic>

</source>


SimpleTransformHtml.java 

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.swing.JOptionPane;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class SimpleTransformHtml
{
 public static void main(String[] args)
    throws TransformerException, TransformerConfigurationException, 
           FileNotFoundException, IOException{  
 TransformerFactory tFactory = TransformerFactory.newInstance();
 String sourceFile = "hello";
 String html = ".html";
 Transformer transformer = tFactory.newTransformer(new StreamSource(sourceFile+xsl));
 transformer.transform(new StreamSource(sourceFile+xml), new StreamResult(new FileOutputStream(sourceFile+html)));
 System.out.println("************* The result is in "+sourceFile+html+" *************");
 Runtime.getRuntime().exec
   ("rundll32 SHELL32.DLL,ShellExec_RunDLL " + sourceFile+html);
  }
}


จะได้ตามด้านล้างนี้

TEST XSLT FOR CREATE WEB SITE BY WONGSAKORN

Hello1, world.
Hello2, world.
Hello3, world.
Hello4, world.
Hello5, world.
I am
fine.

ปริศนา Matrix จตุรัสกล

ปริศนา Matrix จตุรัสกล

จาก http://www.programming.in.th/task/problem.php?pid=1017

จตุรัสกลเป็นตารางขนาด n x n ที่ระบุจำนวนเต็มมีค่าตั้งแต่ 1 ถึง n2 เอาไว้ตามช่องต่าง ๆ ช่องละหนึ่งจำนวน โดยที่ผลรวมของตัวเลขในแนวนอน แนวตั้ง และแนวทแยงจะได้จำนวนเท่ากันเสมอ ตัวอย่างเช่น



จากนิยามของจตุรัสกลดังกล่าว จงเขียนโปรแกรมเพื่อตรวจสอบว่าตารางที่ให้มาเป็นจตุรัสกลหรือไม่

หมายเหตุ: จตุรัสกลที่กล่าวถึงในโจทย์ข้อนี้ จะหมายถึง จตุรัสกลทั่วไป (Normal magic square) ซึ่งจำนวนในแต่ละช่องจะต้องไม่ีซ้ำกัน

ข้อมูลนำเข้า
บรรทัดแรก
เป็นจำนวนเต็ม n (1 <= n <= 10) ใช้กำหนดขนาดของตาราง
บรรทัดที่ 2 ถึง n+1 แต่ละบรรทัดเป็นจำนวนเต็ม n จำนวนซึ่งคั่นด้วยช่องว่างหนึ่งช่อง โดยแต่ละค่ามีค่าอยู่ระหว่าง 1 ถึง n2

ข้อมูลส่งออก
บรรทัดแรก
พิมพ์คำว่า “Yes” ถ้าหากตารางที่ให้มาเป็นจตุรัสกล ไม่เช่นนั้นให้พิมพ์คำว่า “No” โดยไม่มีเครื่องหมายคำพูด

ที่มา: การแข่งขันคณิตศาสตร์ วิทยาศาสตร์ โอลิมปิกแห่งประเทศไทย สาขาวิชาคอมพิวเตอร์ ประจำปี 2547
ตัวอย่างข้อมูลนำเข้า  ตัวอย่างข้อมูลส่งออก
4
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Yes

ความช่วยเหลือ: ไม่มีคำใบ้สำหรับปัญหานี้
สำหรับ input ผมได้ทำเป็น ไฟล์ txt ชื่อ input.txt

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
public class Matrix {
 private ArrayList<String> listinput = new ArrayList<String>();
 private HashMap<Integer, Integer> mapnum = new HashMap<Integer, Integer>();
 int[][] matrix;
 private int size = 0;
 public Matrix(){
  FiletoString("input.txt");
  matrix = new int[size][size];
  System.out.println(size);
  int row = 0;
  for (String str : listinput) {
   String[] allnum = str.split(" ");
   for (int i = 0; i < allnum.length; i++) {
    matrix[row][i] = Integer.parseInt(allnum[i]);
    System.out.print(matrix[row][i]+" ");
   }
   System.out.println();
   row++;
  }
  for(int round = 0;round<2;round++){
   int sum = 0;
   for (int i=0;i<size;i++) {
    if(round==0)
     sum+=matrix[i][i];
    else{
     sum+=matrix[i][size-(i+1)];
    }
   }
   System.out.println(">>"+sum);
   mapnum.put(sum,0);
   for (int i=0;i<matrix.length;i++) {
    sum = 0;
    for (int k=0;k<matrix[i].length;k++) {
     if(round==0)
      sum+=matrix[i][k];
     else
      sum+=matrix[k][i];
    }
    mapnum.put(sum, 0);
    System.out.println(">>"+sum);
   }
  }
  if(mapnum.size()==1)
   System.out.println("Yes");
  else
   System.out.println("No");
 }
 public void FiletoString(String path) {
  try {
   DataInputStream data = new DataInputStream(new FileInputStream(new File(path)));
   int i = 0;
   while(data.available() != 0){
    String read = data.readLine();
    if(i==0)
     size=Integer.parseInt(read);
    else
     listinput.add(read);
    i++;
   }
  } catch (IOException e) {
   System.out.println("File not found "+e.getMessage());
  }
 }
 public static void main(String[] args) {
  new Matrix();
 }
}

Java Read XML

Java Read XML

try {     
            StringBuffer strFile = new StringBuffer();
       DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
       DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
       Document doc = docBuilder.parse (new File(inputfile));
       doc.getDocumentElement ().normalize ();
       NodeList listOfDoc = doc.getElementsByTagName("writer");
       for(int s=0; s<listOfDoc.getLength() ; s++){
        Element firstDocNode = (Element) listOfDoc.item(s);
        String name= firstDocNode.getAttribute("Name");
        System.out.println(name);
       }
   }catch (Throwable t) {
    t.printStackTrace ();
   }


input.xml

<?xml version="1.0"?>
<Document>
 <Title>
  <writer Name="A"/>
  <writer Name="B"/>
  <writer Name="C"/>
  <writer Name="D"/>
  <writer Name="E"/>
  <writer Name="F"/>
  <writer Name="G"/>
  <writer Name="H"/>
 </Title>
</Document>

18 ก.ค. 2554

Eclipse Ctrl+Space - Proposals

หลังจากที่ผมได้โหลดโปรแกรมเขียนจาวายอดนิยม ซึ่งได้ออกเวอร์ชันใหม่มาชื่อว่า Indigo
ซึ่งโปรแกรมตัวนี้เราสามารถโหลด Features เข้ามาได้มากมาย ก็ได้เจอปัญหาคือกด
Ctrl+Space แล้วไม่ขึ้น



ไอ List ที่ใช้อยู่ประจำ พอดีไปเจอวิธีแก้มาอยู่เลยเอามาฝาก ให้ไปที่
Window -> Preferences -> Java -> Editor -> Content Assist -> Advance
 แล้วเลือกตรง
Type Proposals
10  Features ยอดนิยมใน Eclipse Indigo
http://eclipsesource.com/blogs/2011/06/22/top-10-eclipse-indigo-features/