顯示具有 Java 標籤的文章。 顯示所有文章
顯示具有 Java 標籤的文章。 顯示所有文章

2017年8月9日 星期三

2017年3月29日 星期三

[Java] How to import external library

Import external library into .m2 repository.
mvn install:install-file \
 -Dfile=/home/happy/workspace/Java-WebSocket/dist/java_websocket.jar \
 -DgroupId=org.java-websocket \
 -DartifactId=Java-WebSocket \
 -Dversion=1.3.1 \
 -Dpackaging=jar


Java-WebSocket will install in following folder.
/home/happy/.m2/repository/org/java-websocket/Java-WebSocket/1.3.1


Add the following command tell project which external library will be used.

import org.java_websocket.WebSocketImpl;



Add following script into pom.xml file.

<!-- https://mvnrepository.com/artifact/javax.websocket/javax.websocket-api -->
<dependency>
    <groupId>javax.websocket</groupId>
    <artifactId>javax.websocket-api</artifactId>
    <version>1.1</version>
</dependency>

Execute mvn clean install will install javax.websocket-api.

Reference:

2016年7月6日 星期三

2014年12月2日 星期二

[SNMP][JAVA][Open Source] How to compile mibble

[SNMP][JAVA][Open Source] How to compile mibble

Install compiler tool in ubuntu 14.04
sudo apt-get install ant
sudo apt-get install openjdk-7-jdk

Under mibble-2.9.3 then run
ant -buildfile build.xml

... 

doc-html:                                                                                                                                                                  [0/1956]
     [copy] Copying 1 file to /home/freeman/Downloads/mibble-2.9.3/doc
     [xslt] Transforming into /home/freeman/Downloads/mibble-2.9.3/doc
     [xslt] Processing /home/freeman/Downloads/mibble-2.9.3/src/doc/release/authors.xml to /home/freeman/Downloads/mibble-2.9.3/doc/authors.html
     [xslt] Loading stylesheet /home/freeman/Downloads/mibble-2.9.3/src/doc/html.xsl
     [xslt] Warning:  org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
     [xslt] Warning:  org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
     [xslt] Processing /home/freeman/Downloads/mibble-2.9.3/src/doc/release/bugs.xml to /home/freeman/Downloads/mibble-2.9.3/doc/bugs.html
     [xslt] Processing /home/freeman/Downloads/mibble-2.9.3/src/doc/release/features.xml to /home/freeman/Downloads/mibble-2.9.3/doc/features.html
     [xslt] Processing /home/freeman/Downloads/mibble-2.9.3/src/doc/release/index.xml to /home/freeman/Downloads/mibble-2.9.3/doc/index.html
     [xslt] Processing /home/freeman/Downloads/mibble-2.9.3/src/doc/release/install.xml to /home/freeman/Downloads/mibble-2.9.3/doc/install.html
     [xslt] Processing /home/freeman/Downloads/mibble-2.9.3/src/doc/release/version.xml to /home/freeman/Downloads/mibble-2.9.3/doc/version.html

doc-java:
  [javadoc] Generating Javadoc
  [javadoc] Javadoc execution
  [javadoc] Loading source files for package net.percederberg.mibble...
  [javadoc] Loading source files for package net.percederberg.mibble.snmp...
  [javadoc] Loading source files for package net.percederberg.mibble.type...
  [javadoc] Loading source files for package net.percederberg.mibble.value...
  [javadoc] Constructing Javadoc information...
  [javadoc] Standard Doclet version 1.7.0_65
  [javadoc] Building tree for all the packages and classes...
  [javadoc] Building index for all the packages and classes...
  [javadoc] Building index for all classes...

doc:

all:

BUILD SUCCESSFUL
Total time: 22 seconds

Compile specific function
ant -buildfile build.xml doc-html

Buildfile: /home/freeman/Downloads/mibble-2.9.3/build.xml

doc-html:
     [xslt] Transforming into /home/freeman/Downloads/mibble-2.9.3/doc

BUILD SUCCESSFUL
Total time: 0 seconds

Reference :
1. mibble :: MIB Parser

2014年11月20日 星期四

2012年7月8日 星期日

[NetBean][Java]  Load mysql-connector-java-5.1.6.jar into BeanNet


[NetBean][Java]  Load mysql-connector-java-5.1.6.jar into BeanNet



[Purpose]

Java code connect with Mysql.



1. Download mysql-connector-java-5.1.6.jar from internet

Laod this file into NetBean.



Right click





Select java file





Then will see package into NetBean.

When save some data into Mysql will successfully.



2012年6月19日 星期二

[POS] POS learning track

Database :
Mysql teach:
  1. [mysql] input data to database
JAVA tutor :
  1. POS教學影片
  2. Swing JFC
  3. Teach you lot of Java skill (Youtube)
Java Teach :
Java mysql :
NetBeans :

2011年11月15日 星期二

[JavaScript] Use jsDraw2D library to draw.


Use jsDraw2D library to draw.



<script type="text/JavaScript">



//Create jsGraphics object

var gr = new jsGraphics(document.getElementById("canvas"));



//Create jsColor object

var col = new jsColor("blue");

var col2 = new jsColor("green");

var col3 =  new jsColor("#DCDCDC");

//Create jsPen object

var Line1 = new jsPen(col,25);

var Line2 = new jsPen(col2,25);



//Draw a background color

var d = new jsPoint(10,220);

gr.fillRectangle(col3,d,750,200);



//Draw a Download Comment Mark between 2 points

var Blue_Comment = new jsPen(col,20);

var Download_Comment_Start_Point = new jsPoint(20,230);

var Download_Comment_End_Point = new jsPoint(40,230);

gr.drawLine(Blue_Comment,Download_Comment_Start_Point,Download_Comment_End_Point);

gr.drawText("&nbsp;&nbsp;&nbsp;&nbsp;Download",Download_Comment_End_Point);



//Draw a Upload Comment Mark between 2 points

var Green_Comment = new jsPen(col2,20);

var Upload_Comment_Start_Point = new jsPoint(150,230);

var Upload_Comment_End_Point = new jsPoint(170,230);

gr.drawLine(Green_Comment,Upload_Comment_Start_Point,Upload_Comment_End_Point);

gr.drawText("&nbsp;&nbsp;&nbsp;&nbsp;Upload",Upload_Comment_End_Point);



//Draw a Download Speed Rate between 2 points

var Download_Start_Point = new jsPoint(10,300);

var Download_End_Point = new jsPoint(600,300);

gr.drawLine(Line1,Download_Start_Point,Download_End_Point);

gr.drawText("&nbsp;&nbsp;&nbsp;&nbsp;3M bps",Download_End_Point);



//Draw a Upload Speed Rate between 2 points

var Upload_Start_Point = new jsPoint(10,350);

var Upload_End_Point = new jsPoint(200,350);

gr.drawLine(Line2,Upload_Start_Point,Upload_End_Point);

gr.drawText("&nbsp;&nbsp;&nbsp;&nbsp;43K bps",Upload_End_Point);





</script>

2011年8月17日 星期三

[java] mouseclick function


// Show jTable1 element use MouseClick function   



private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {

        // TODO add your handling code here:

        

        int row = jTable1.getSelectedRow();

        int column = 1;

        

        String message = jTable1.getValueAt(row, column).toString();

        

        JOptionPane.showMessageDialog(null, message);

    }



 



Reference :



[java] set display on the meddle of screen


//        set display on the meddle of screen

        this.setSize(1024,768);

        Dimension di = Toolkit.getDefaultToolkit().getScreenSize();

        

//        divide 2 can put the screen in the middle

        setLocation( ( di.width -1024  )/2 , (di.height - 768  )/2    );



Java Teach :



jTable Java Swing p4


2011年8月11日 星期四

[java] (16) List all data in jTable from database, Edit Cell and store it


class MyTableModel extends AbstractTableModel

  {



//     import java.util.*;  

       private ArrayList<String> colname;

       private ArrayList<ArrayList> data;



       public MyTableModel(ResultSet rs)

       {

          try{



             // 取得欄位數量

             ResultSetMetaData rm = rs.getMetaData();

             int cnum = rm.getColumnCount();

             colname = new ArrayList<String>(cnum);



             // 取得欄位名稱

             for(int i=2; i<=cnum; i++){

                colname.add(rm.getColumnName(i));

             }



             // 取得列

             data = new ArrayList<ArrayList>();

        

             while(rs.next()){

               

                ArrayList<String> rowdata = new ArrayList<String>();

                for(int i=2; i<=cnum; i++){

                   System.out.println("happy1  int i=2; i<=cnum; i++ ");

                   rowdata.add(rs.getObject(i).toString());

                }

           

                data.add(rowdata);

                System.out.println("afdafads");

                System.out.println(data);

             }            

           }

           catch(Exception e){

              e.printStackTrace();

          }

          

        

         

       }

       

           /*

     * Don't need to implement this method unless your table's

     * editable.

     */

     



      // This one can edit the cell

       public boolean isCellEditable(int row, int col) {

        //Note that the data/cell address is constant,

        //no matter where the cell appears onscreen.

            return true;

      

       }




    public void setValueAt(Object value, int row, int col) {

       

            System.out.println(value.getClass());

            System.out.println("setValueAt Row is :" + row);

            System.out.println("setValueAt col is :" + col);

            System.out.println("setValueAt :" + value);

            



            // After edit cell can store the data into table

            ArrayList rowdata = (ArrayList)data.get(row);

            System.out.println((ArrayList)data.get(row));

            rowdata.set(col, value);

            System.out.println(rowdata.get(col));




        }

        




       public int getRowCount()

       {



           

          System.out.println("getRowCount() data.size :"+data.size());

                       

          return data.size();

       }

       public int getColumnCount()

       {

          System.out.println("getColumnCount() colname.size :"+colname.size());

          return colname.size();

       }



       public Object getValueAt(int row, int column)

       {

          System.out.println("getValueAt");

          ArrayList rowdata = (ArrayList)data.get(row);

          

          

          System.out.println("rowdata :" + rowdata);

          return rowdata.get(column);

       }

       public String getColumnName(int column)

       {

          System.out.println("getColumnName");

          return (String) colname.get(column);



       }

   }

    

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        Connection conn = null;

        String url = "jdbc:mysql://localhost:3306/sale?useUnicode=true&characterEncoding=big5";

        String user = "testuser";

        String password = "test623";



        try {





            conn = DriverManager.getConnection(url, user, password);



            Statement st = conn.createStatement();

            

//            String qry = "SELECT * FROM total_calc";

//            String qry = "SELECT * FROM total_calc";

              String qry = "SELECT * FROM tabaco_product order by Tabaco_order " ;

            ResultSet rs = st.executeQuery(qry);

            

                        if (rs.last()){

                   int i = rs.getRow();

                    System.out.println(i);

                    

                    

               System.out.println(rs.last());    

               rs.first();

               

            }

          

 









 



            // put My TableModel(rs) into setModel

            data_jTable1.setModel(new MyTableModel(rs));





            

            rs.close();        

            st.close();

            conn.close();

            

        } catch (SQLException ex) {

            System.out.println(ex.getMessage());

        }

        

        

        

    }                              


2011年8月9日 星期二

2011年8月8日 星期一

[java] (15) jComboBox connect to mysql


public void jComboBox_connect_mysql (){

       

             Connection conn = null;

        String url = "jdbc:mysql://localhost:3306/sale?useUnicode=true&characterEncoding=big5";

        String user = "testuser";

        String password = "test623";



        try {



            conn = DriverManager.getConnection(url, user, password);

            Statement st = conn.createStatement();

            

            

            ResultSet rs = st.executeQuery( "SELECT * FROM tabaco_product " );

            



           try{

           while (rs.next()) {

                jComboBox1.addItem(rs.getString("Tabaco_name"));

           } // while

           }catch(ArrayIndexOutOfBoundsException e){}


 

           

           

            rs.close();

            

   

            

            st.close();

            conn.close();

            

        } catch (SQLException ex) {

            System.out.println(ex.getMessage());

        }

        

        

    

    }


[java] (14) Update the data of mysql with java code (NetBean )


private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:



Connection conn = null;

PreparedStatement pstm = null;



String url = "jdbc:mysql://localhost:3306/sale?useUnicode=true&characterEncoding=big5";

String user = "testuser";

String password = "test623";



// Calendar date = Calendar.getInstance();

// SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd");







try{

conn = DriverManager.getConnection(url, user, password);

Statement st = conn.createStatement();





for (int i=0 ;i
try {



String Shift_Data = Shift_jComboBox2.getSelectedItem().toString();



String Data_Year = Year_jComboBox2.getSelectedItem().toString();

String Data_Month = Month_jComboBox3.getSelectedItem().toString();

String Data_Day = Day_jComboBox4.getSelectedItem().toString();

String Date_Data = Data_Year +"-"+ Data_Month +"-"+ Data_Day;



String Goods_name_Data = jTable1.getValueAt(i,0).toString();

String Unit_price_Data = jTable1.getValueAt(i,1).toString();

String Stocks_DataC = jTable1.getValueAt(i,2).toString();

String Good_in_stock_DataD = jTable1.getValueAt(i,3).toString();

String Ship_DataE = jTable1.getValueAt(i,4).toString();

String Balance_DataF = jTable1.getValueAt(i,5).toString();

String Selling_goods_DataG = jTable1.getValueAt(i,6).toString();

String Subtotal_DataH = jTable1.getValueAt(i,7).toString();

String Space_reserve_DataI = jTable1.getValueAt(i,8).toString();



String query = "update total_calc set Stocks= ?, Good_in_stock= ?, Ship= ?, Balance= ?, Selling_goods= ?, Subtotal= ?, Space_reserve= ? where Date = ? and Shift = ? and Goods_name= ? " ;

//綠色 是要變更的項目 藍色 是 所選擇的項目 選項越多 越精準

// green color is the item which we want to change. Blue color is the item which we want green color //item to change. More condition is better. Between item and item use "and".

// System.out.println(Data);

pstm = conn.prepareStatement(query);



System.out.println(Date_Data);





pstm.setString(1,Stocks_DataC);//按照上面?的順序 (follow the question mark on the //above.)

pstm.setString(2,Good_in_stock_DataD);

pstm.setString(3,Ship_DataE);

pstm.setString(4,Balance_DataF);

pstm.setString(5,Selling_goods_DataG);

pstm.setString(6,Subtotal_DataH);

pstm.setString(7,Space_reserve_DataI);



pstm.setString(8, Date_Data );

pstm.setString(9,Shift_Data);

pstm.setString(10,Goods_name_Data);

System.out.println(Goods_name_Data);







System.out.println("happy");

pstm.executeUpdate();







}catch(NullPointerException e){

// jTable1.setValueAt(0, i, j);

// JOptionPane.showMessageDialog(null,("第"+ (i+1) + "行 \n 第"+ (j+1)+ "行 \n 沒有輸入資料" ) );

}







}







pstm.close();

st.close();

conn.close();

}catch (SQLException ex) {

System.out.println(ex.getMessage());

}



JOptionPane.showMessageDialog(null,("資料傳送到 資料庫 完成" ) );

}


2011年8月7日 星期日

[java] build jar and become excutable file in windows

tar dist folder. And copy this to windows any folder.
dist this folder include lib.

recompress this compressed file.

And download this file(jarfix 1.2.0) into dist fold.

And excute this file.

If computer don't have any java runtime program.
Will download from java website.

when finish install java runtime program.
Excute jarfix again.
XXX.jar become excutable file.

2011年8月6日 星期六

[java] (13) get data from database and put data into jTable


    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        Connection conn = null;



        

        String url = "jdbc:mysql://localhost:3306/sale?useUnicode=true&characterEncoding=big5";

        String user = "testuser";

        String password = "test623";

        





        

        try{

           conn = DriverManager.getConnection(url, user, password);

           Statement st = conn.createStatement();

           

           

           String Data_Shift = jComboBox1.getSelectedItem().toString();

           String Data_Year  = Year_jComboBox2.getSelectedItem().toString();

           String Data_Month = Month_jComboBox3.getSelectedItem().toString();

           String Data_Day   = Day_jComboBox4.getSelectedItem().toString();

           



//    ResultSet rs = st.executeQuery( "SELECT Balance FROM total_calc where Shift= '早班' and Date= '2011_08_07' "); 要注意裡面有有點 ‘ ’







// ResultSet rs     rs前面要有ResultSet 整行才算完整

           ResultSet rs = st.executeQuery( "SELECT Balance FROM total_calc where Shift ='"+ Data_Shift  +"' and Date ='"+ Data_Year   +"-"+ Data_Month  +"-"+ Data_Day +"'" );

           

            



           

         //  SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';

           

           int li_row = 0;

           while (rs.next()) {



// 因為rs.getString(1)  1是因為只有抓 Balance  資料,所以放在第一列裡面

//如果是 select * from table  因為抓好幾列資料,所以要指定那一列要顯示






                jTable1.setValueAt(rs.getString(1),li_row,3);





                li_row ++;

           } // while

        

           

           

           

            rs.close();             

            st.close();

            conn.close();

        }catch (SQLException ex) {

         System.out.println(ex.getMessage());

        }

    }



 



Reference:


[java] (12) select jCombBox and put selected item into database


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        

        Connection conn = null;

        PreparedStatement pstm = null;

        

        String url = "jdbc:mysql://localhost:3306/sale?useUnicode=true&characterEncoding=big5";

        String user = "testuser";

        String password = "test623";

        

         Calendar date = Calendar.getInstance();

         SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd");





        

        try{

           conn = DriverManager.getConnection(url, user, password);

           Statement st = conn.createStatement();

            

           

           for (int i=0 ;i<jTable1.getRowCount();i++){

//               for (int j=0 ; j<jTable1.getColumnCount();j++){

                    try {

                        

                    String DataZ = jComboBox1.getSelectedItem().toString();    //讀取 jComboBox1所選擇的項目,然後放入資料庫中

                    String DataA = jTable1.getValueAt(i,0).toString();

                    String DataB = jTable1.getValueAt(i,1).toString();

                    String DataC = jTable1.getValueAt(i,2).toString();

                    String DataD = jTable1.getValueAt(i,3).toString();

                    String DataE = jTable1.getValueAt(i,4).toString();

                    String DataF = jTable1.getValueAt(i,5).toString();

                    String DataG = jTable1.getValueAt(i,6).toString();

                    String DataH = jTable1.getValueAt(i,7).toString();

                    String DataI = jTable1.getValueAt(i,8).toString();

                    

//                     System.out.println(Data);

                     pstm = conn.prepareStatement("insert into total_calc "

                             + "(Shift,Goods_name,Unit_price,Stocks,Good_in_stock,Ship,Balance,Selling_goods,Subtotal,Space_reserve,Date) "

                             + "values  (?,?,?,?,?,?,?,?,?,?,? )" );

                     

                     pstm.setString(1,DataZ);

                     pstm.setString(2,DataA);

                     pstm.setString(3,DataB);

                     pstm.setString(4,DataC);

                     pstm.setString(5,DataD);

                     pstm.setString(6,DataE);

                     pstm.setString(7,DataF);

                     pstm.setString(8,DataG);

                     pstm.setString(9,DataH);

                     pstm.setString(10,DataI);

                     pstm.setString(11, dateformatter.format(date.getTime()) );

                     

                     pstm.executeUpdate();

                     



                    }catch(NullPointerException e){

//                      jTable1.setValueAt(0, i, j);

//                      JOptionPane.showMessageDialog(null,("第"+ (i+1) + "行 \n 第"+ (j+1)+ "行 \n 沒有輸入資料" ) );

                    }

//             }

 

           }

           



             

            pstm.close();           

            st.close();

            conn.close();

        }catch (SQLException ex) {

         System.out.println(ex.getMessage());

        }

        

        

    }   



Reference:


[java] (11) put data into database from jTable


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        // TODO add your handling code here:

        

        Connection conn = null;

        PreparedStatement pstm = null;

        

        String url = "jdbc:mysql://localhost:3306/sale?useUnicode=true&characterEncoding=big5";

        String user = "testuser";

        String password = "test623";

        



        //Sql 所吃的時間格式 String

         Calendar date = Calendar.getInstance();

         SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd");






        

        try{

           conn = DriverManager.getConnection(url, user, password);

           Statement st = conn.createStatement();

            

           

           for (int i=0 ;i<jTable1.getRowCount();i++){



                    try {



                  // 抓出資料

                    String DataA = jTable1.getValueAt(i,0).toString();

                    String DataB = jTable1.getValueAt(i,1).toString();

                    String DataC = jTable1.getValueAt(i,2).toString();

                    String DataD = jTable1.getValueAt(i,3).toString();

                    String DataE = jTable1.getValueAt(i,4).toString();

                    String DataF = jTable1.getValueAt(i,5).toString();

                    String DataG = jTable1.getValueAt(i,6).toString();

                    String DataH = jTable1.getValueAt(i,7).toString();

                    String DataI = jTable1.getValueAt(i,8).toString();

                    

                   // 所要放入的格式

                     pstm = conn.prepareStatement("insert into total_calc "

                             + "(Goods_name,Unit_price,Stocks,Good_in_stock,Ship,Balance,Selling_goods,Subtotal,Space_reserve,Date) "

                             + "values  (?,?,?,?,?,?,?,?,?,? )" );





                     // 資料一個一個放入

                     pstm.setString(1,DataA);

                     pstm.setString(2,DataB);

                     pstm.setString(3,DataC);

                     pstm.setString(4,DataD);

                     pstm.setString(5,DataE);

                     pstm.setString(6,DataF);

                     pstm.setString(7,DataG);

                     pstm.setString(8,DataH);

                     pstm.setString(9,DataI);

                     pstm.setString(10, dateformatter.format(date.getTime()) );

                     

                     pstm.executeUpdate(); //存完之後,馬上加到sql裡面

                     



                    }catch(NullPointerException e){

//                      jTable1.setValueAt(0, i, j);

//                      JOptionPane.showMessageDialog(null,("第"+ (i+1) + "行 \n 第"+ (j+1)+ "行 \n 沒有輸入資料" ) );

                    }

 

           }

           



             

            pstm.close();           

            st.close();

            conn.close();

        }catch (SQLException ex) {

         System.out.println(ex.getMessage());

        }

        

        

    }                                        



Reference:


[java] (11) Make execute file

Make execute file :

NetBean --> Run --> Build project --> java -jar "/home/luke/test5/POS_system/dist/POS_system.jar"

Already have one file call POS_system.jar at /home/luke/test5/POS_system/dist/ .
go to /home/luke/test5/POS_system/dist/

And type
Change file type to execution file.
And execute it.


luke@luke-MS-6657:~/test5/POS_system/dist$ chmod 777 ./POS_system.jar
luke@luke-MS-6657:~/test5/POS_system/dist$ ./POS_system.jar