<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Javaphua Blog

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      46 Posts :: 5 Stories :: 46 Comments :: 0 Trackbacks

    ???
    //格式化日期為指定的格式
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");

    format.format(rs.getTimestamp("birth"))

    //將字串符轉換成日期類型
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ?java.util.Date date = format.parse("1981-10-25 10:20:25");

    //在數據庫中將字符串轉成日期存入數據庫
    birth=to_date(?,'YYYY-MM-DD HH24:MI:SS')

    //發送SQL語句,執行存儲過程
    java.sql.CallableStatement cs = con.prepareCall("{call addAge}")

    //更新時使用數據庫的系統時間(sysdate)
    "update student set birth=sysdate"

    //IO的幾種常用通信方法---------------采用對象方式進行傳輸數據-------------------------
    java.io.BufferedReader in = new java.io.BufferedReader(
    ??new java.io.InputStreamReader(socket.getInputStream()//System.in));


    java.io.PrintWriter out = new java.io.PrintWriter(
    ?new java.io.OutputStreamWriter(new java.io.BufferedOutputStream(
    ?socket.getOutputStream())));

    java.io.ObjectOutputStream out? = new java.io.ObjectOutputStream(
    ??new java.io.BufferedOutputStream(new java.io.FileOutputStream("t.dat")));
    out.writeObject(s);
    ??out.flush();
    ??out.close();
    java.io.ObjectInputStream in = new java.io.ObjectInputStream(
    ??new java.io.BufferedInputStream(new java.io.FileInputStream("t.dat")));
    ?Student ss = (Student)in.readObject();

    --------------------------------------------------------------
    //給按鈕添加事件 按鈕觸發數字自動滾動

    this.button.addActionListener(
    ??new java.awt.event.ActionListener(){
    ?????
    ??public void actionPerformed(java.awt.event.ActionEvent e){
    ???new Thread(){
    ????? ??
    ????public void run(){
    ?????? while(true){
    ????? ?String s=txt.getText();
    ????? ?char c=s.charAt(s.length()-1);
    ????? ?String cs=s.substring(0,s.length()-1);
    ????? ?txt.setText(c+cs);
    ????? ?try{
    ????? ?Thread.sleep(1000);
    ????? ?}catch(Exception y){}
    ????? }?
    ????}
    ???}.start();
    ??}
    ?}
    );

    ----------------------------------------

    另一種添加事件的方法
    button1.addActionListener( new CalculationListener());

    //在剪切時候,它在一個內部類
    class CalculationListener implements java.awt.event.ActionListener{
    ?public void actionPerformed(java.awt.event.ActionEvent e){
    ??javax.swing.JButton button? = (javax.swing.JButton)e.getSource();
    ???calc.calculate(button.getText());
    ??}
    }

    -----------------------------------------
    啟動線程的幾種方法..
    ----------------------------

    ??R1 r = new R1();
    ??R1 w = new R1();
    ??Thread t = new Thread(r);
    ??Thread q = new Thread(w);
    ??t.start();
    ??q.start();

    ??new Thread(new W(socket)).start();

    class R1 implements Runnable{
    ?public void run(){
    ??
    ?}
    }
    -----------------------------------
    Thread1 t1 =new Thread1();
    t1.start();

    class Thread1 extends Thread{
    ?public void run(){
    ??
    ?}
    }

    命名線程://Thread t2 = new Thread(new Thread3(10),"線程名")
    得到線程序號:System.out.println (t2.getPriority());


    ?applet框架
    -----------------------------
    public class TestApplet extends javax.swing.JApplet{
    ?public? void init(){
    ??super.init();
    ?}

    }

    //設置窗口關閉時自動退出
    this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

    ------------------------------------------在lesson中有一個鼠標事件還沒有看通,有點復雜(day16)

    //給按鈕添加事件的一種方法
    ? ?//按鈕調用
    ?button.addActionListener(new count2());
    ?//事件類繼承監聽器
    ?class count2 implements java.awt.event.ActionListener{
    ???public void actionPerformed(java.awt.event.ActionEvent e){
    ????counter();?
    ???}
    ??
    ?}
    ?//方法與其分開
    ?public void counter(){
    ??String s = jt1.getText();
    ??String m = jt2.getText();
    ??int n = Integer.parseInt(m);
    ??int u = Integer.parseInt(s);
    ??int w = n+u;
    ?
    ??jt3.setText(""+w);
    ?}


    //為了代碼與窗體進行分開合作工作,因此將方法嵌入窗體中(“你中用我 我中有你”)
    如:LotteryFunction lf = new LotteryFunction(this);

    LotteryFunction 為功能類

    將this作為工功能類構造的參數可很方便的在窗體顯示計算結果

    ------------------------------------------------------------------------------

    如面板上有多個控件時,可用以下方法將其加入面板中
    class MyPanel extends javax.swing.JPanel{
    ???javax.swing.JTextField[] texts = new javax.swing.JTextField[7];
    ???
    ???MyPanel(){
    ????this.setLayout(new java.awt.GridLayout(1,7,3,3));
    ????
    ????for(int i=0;i<texts.length;i++){
    ?????texts[i] = new javax.swing.JTextField();
    ?????texts[i].setBackground(java.awt.Color.green);
    ?????this.add(texts[i]);
    ????}
    ???}
    }

    ------------------------------------------------------------
    排序的代碼:

    static int t;
    int[] r ={8,9,7,6,5,4,3};
    for(int i=0;i<r.length;i++){
    ?for(int j=1;j<r.length-i;j++){
    ??if(r[j]<r[j-1]){
    ??? t=r[j];
    ??? r[j]=r[j-1];
    ??? r[j-1]=t;?
    ??}
    ?}
    }

    --------------------------

    如何給文件進行鎖定


    public static void lock()throws Exception{
    ? ??java.io.FileOutputStream out = new java.io.FileOutputStream("c:\\TestIO.txt",true);
    ? ??java.nio.channels.FileChannel f = out.getChannel();
    ? ??
    ? ??java.nio.channels.FileLock lock = f.tryLock();
    ? ??
    ? ??if (lock!=null){
    ? ???System.out.println ("正在鎖定");
    ? ???Thread.sleep(100000);
    ? ???System.out.println ("解除完畢");
    ? ???lock.release();?
    ? ??}
    ?}

    ------------------------------
    java.nio 如何進行文件傳輸的

    java.io.FileInputStream in? = new java.io.FileInputStream("TestNIO.java");
    ? ?java.nio.channels.FileChannel ch = in.getChannel();
    ? ?java.nio.ByteBuffer buff? = java.nio.ByteBuffer.allocate(1024);
    ? ?while((ch.read(buff))!=-1){
    ? ??buff.flip();
    ? ??java.nio.charset.Charset ca = java.nio.charset.Charset.forName("gb2312");
    ?????//對緩存進行編碼設置后,再進行解析
    ? ??java.nio.CharBuffer cb = ca.decode(buff);
    ? ??System.out.println (cb);
    ? ??buff.clear();
    ??}

    ---------------文件傳輸
    public static void copyfile()throws Exception{
    ? ??java.io.FileInputStream in? = new java.io.FileInputStream("TestNIO.java");
    ? ??java.nio.channels.FileChannel ch = in.getChannel();
    ? ??
    ? ??java.io.FileOutputStream out = new java.io.FileOutputStream("c:\\TestIO.java");
    ? ??java.nio.channels.FileChannel outch = out.getChannel();
    ? ??
    ? ??java.nio.ByteBuffer buff = java.nio.ByteBuffer.allocate(32);
    ? ??
    ? ??while((ch.read(buff))!=-1){
    ? ???buff.flip();
    ? ???outch.write(buff);
    ? ???buff.clear();
    ? ???
    ? ??}
    ? ??in.close();
    ? ??out.close();
    ? ??
    ? }
    -------------------------------???關于java.nio.buff中的一些緩沖區的管理代碼還沒有看懂??


    幾種IO通信方法
    1---------
    java.io.BufferedInputStream in =new java.io.BufferedInputStream(
    ?????????new java.io.FileInputStream("TestIO.java"));
    ???
    java.io.BufferedOutputStream out =new java.io.BufferedOutputStream(
    ?????????new java.io.FileOutputStream("c:\\t.txt"));

    byte[] b =new byte[32];
    ??
    ??int len= 0 ;
    ??while((len=in.read(b))!=-1){
    ???out.write(b,0,len);
    ?????
    ??}
    ??out.flush();
    ??in.close();
    ??out.close();

    2-----------

    java.io.FileReader f =new java.io.FileReader("c:\\t.txt");
    ??char[] c = new char[32];
    ??int len=0;
    ??while((len=f.read(c))!=-1){
    ???System.out.println (new String(c,0,len));
    ??}
    ??
    ?f.close();

    3------------------
    java.io.BufferedReader r= new java.io.BufferedReader(new java.io.FileReader("TestIO.java"));
    ?
    java.io.PrintWriter w= new java.io.PrintWriter(new java.io.BufferedWriter(new java.io.FileWriter("c:\\t.txt")));
    ?
    ?
    ?String line=null;
    ?
    ?while((line =r.readLine())!=null){
    ??w.println(line);
    ??
    ?}
    ??w.flush();
    ??r.close();
    ??w.close();

    4-----------------------
    java.io.PrintWriter p = new java.io.PrintWriter(new java.io.BufferedWriter(
    ?????????//是否在文件后進行追加數據(true)
    ?????new java.io.FileWriter("c:\\t.txt",true)));
    ??p.print("12");
    ??p.flush();

    5------------------------
    java.io.FileOutputStream out? = new java.io.FileOutputStream("c:\\t.txt");
    ???
    ???java.io.OutputStreamWriter write = new java.io.OutputStreamWriter(out,"UTF-8");
    ???
    ???write.write("2222222222");
    ???
    ???write.close();
    5---------------------------從控制臺讀取數據
    java.io.BufferedReader r? = new java.io.BufferedReader(
    ??????new java.io.InputStreamReader(System.in));
    ??????
    ??String s=r.readLine();
    ??System.out.println (s);

    6-------------------------------向文件寫入數字
    int i = 0;
    ??java.io.DataOutputStream out? =new java.io.DataOutputStream(
    ??????new java.io.BufferedOutputStream(new java.io.FileOutputStream("c:\\t.txt")));?
    ??
    ??out.writeInt(1);
    ??out.writeChar('a');
    ??out.writeInt(2);
    ??out.writeChar('b');
    ??//out.writeInt(4);
    ??out.flush();
    ??out.close();
    ??
    ??java.io.DataInputStream in =new java.io.DataInputStream(
    ??????new java.io.BufferedInputStream(new java.io.FileInputStream("c:\\t.txt")));
    ??while(i!=-1){
    ???System.out.println (i=in.readInt());
    ???//System.out.println (in.readDouble());
    ???System.out.println (in.readChar());?
    ??}?

    7---------------------------------未看懂的代碼????????????
    java.io.RandomAccessFile r = new java.io.RandomAccessFile("c:\\t.txt","r");
    ???
    ???System.out.println (r.readInt());
    ???r.seek(0);
    ???System.out.println (r.readInt());
    ???r.seek(r.length()-8);
    ???System.out.println (r.readDouble());
    ???r.seek(r.length()-11);
    ???System.out.println (r.readUTF());??

    //壓縮解壓文件的代碼--還未看

    ?public static void ZipFile()throws Exception{
    ???java.io.BufferedInputStream b = new java.io.BufferedInputStream(
    ????new java.io.FileInputStream("c:\\t.txt"));
    ????
    ???java.util.zip.ZipOutputStream z = new java.util.zip.ZipOutputStream(
    ????new java.io.BufferedOutputStream(new java.io.BufferedOutputStream(
    ?????new java.io.FileOutputStream("c:\\t.zip"))));
    ?????
    ???z.putNextEntry(new java.util.zip.ZipEntry("test.txt"));
    ???
    ???byte[] t = new byte[32];
    ???int len = 0;
    ???while((len=b.read(t))!=-1){
    ????z.write(t,0,len);//z.write(t);
    ???}
    ???
    ???z.flush();
    ???b.close();
    ???z.close();
    ?}?

    ----------
    public static void unzip()throws Exception{
    ???java.util.zip.ZipFile? zip = new java.util.zip.ZipFile("c:\\t.zip");
    ???
    ???java.util.Enumeration enu = zip.entries();
    ???
    ???while(enu.hasMoreElements()){
    ??? ?java.util.zip.ZipEntry entry = (java.util.zip.ZipEntry)enu.nextElement();
    ??? ?java.io.InputStream in = zip.getInputStream(entry);
    ??? ?
    ??? ?java.io.BufferedOutputStream out = new java.io.BufferedOutputStream(
    ??? ???new java.io.FileOutputStream("c:\\test.txt"/*+entry.getName()*/));
    ??? ???
    ??? ?byte[] b = new byte[32];
    ??? ?int len =0;
    ??? ?while((len=in.read(b))!=-1){
    ??? ?? out.write(b,0,len);
    ??? ?}
    ???}
    ??}

    ------------------從控制臺向文件輸入數據

    java.io.BufferedReader? in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
    ? ? java.io.PrintStream out =new java.io.PrintStream(new java.io.BufferedOutputStream(new java.io.FileOutputStream("test.log")));
    ? ?// System.setErr(out);//可以使輸入轉向
    ? ?// System.setOut(out);//可以使輸入轉向
    ? ? while(true){
    ? ? ?out.println(in.readLine());
    ? ? ?out.flush();

    ---------------------添加多的一個“\”表示轉義符
    java.io.File f2 = new java.io.File("c:\\test\\a\\b\\c");

    實現文件類型的過濾方法-------1

    String[] list = f2.list();
    ?System.out.println (java.util.Arrays.asList(list));
    ?list = f2.list(
    ??new java.io.FilenameFilter(){
    ???public boolean accept(java.io.File dir,String name){
    ????return name.endsWith(".java");
    ???}?
    ??}
    ?);

    ----------------------------2( 多個過濾方式)
    String[] list = f2.list();
    ? list =f2.list(
    ??new java.io.FilenameFilter(){
    ???public boolean accept(java.io.File dir,String names){
    ??????
    ????boolean java= names.endsWith(".java");
    ????boolean txt = names.endsWith(".txt");
    ????return java || txt;
    ???}
    ??}?
    ?);

    //String[] list = f2.list();
    java.util.Arrays.asList(list)將數組轉成ArrayList

    --------------------------------------------------刪除有文件的目錄實用代碼

    public static void delDir(java.io.File dir){
    ?if(dir.isFile()){
    ??dir.delete();
    ?}else{
    ??java.io.File[] fis = dir.listFiles();
    ???for(int i=0;i<fis.length;i++){
    ????delDir(fis[i]);
    ???}
    ??dir.delete();
    ?}
    }
    ------------------------------------------------------計算文件夾大小代碼

    ?System.out.println ("文件大小 "+s/1024+"? kB"+" = "+(float)s/1024/1024+"M");


    ?public? static double len(java.io.File dir){
    ??double s=0,len=0;
    ???if(dir.isFile()){
    ????s=dir.length();
    ???}else{
    ????java.io.File[] file = dir.listFiles();
    ????for(int i=0;i<file.length;i++){
    ?????len+=len(file[i]);
    ????}
    ???}
    ???return len+s;
    ?}

    --------------------------------------------------------幾種集合類的使用

    java.util.ArraryList list=new java.util.ArraryList();
    ?? ??list.add("abc");
    ??list.size();
    ??list.iterator();

    java.util.HashSet set = new java.util.HashSet();
    ??for(int i=0;i<10;i++){
    ???set.add("abc"+i);
    ??}
    ??
    java.util.Iterator it = set.iterator();
    ??while(it.hasNext()){
    ???System.out.println (it.next());
    ??}
    ?
    java.util.HashMap map = new java.util.HashMap();
    ??map.put(new Integer(1),"002");
    ??map.put(new Integer(4),"001");
    ??System.out.println (map.get(new Integer(1)));
    ??System.out.println (map.get(new Integer(4)));
    ??
    java.util.Set keys = map.keySet();//返回一個SET集合
    ??it=keys.iterator();
    ?while(it.hasNext()){
    ??Object o = it.next();
    ?? System.out.println (o+":"+map.get(o));
    ?}
    -------------系統屬性的操作

    java.util.Properties p = new java.util.Properties();
    ??FileInputStream f = new FileInputStream("c:\\a.properties");
    ??
    ??p.load(f);
    ??System.out.println (p.get("test.author"));
    ??System.out.println (p.get("test.version"));
    ??
    ??p.setProperty("test.author","llldiadsfsa");
    ??p.setProperty("test.address","meimei");
    ??p.setProperty("test.version","10.0");
    ??
    ??java.io.FileOutputStream out = new FileOutputStream("c:\\a.properties");
    ??p.save(out,"ruanwei");
    ??
    ??//p.store(out,"test");
    ??out.close();
    ---------------------------------------------------------------未懂代碼:以后再看????////
    ?String str1 = args[0];
    ??String str2 = args[1];?????????????????
    ??
    ??if("int".equals(System.getProperty("precition"))){
    ???int i1 = Integer.parseInt(str1);
    ???int i2 = Integer.parseInt(str2);
    ???System.out.println ("i1"+"/"+"i2"+"="+divide(i1,i2));
    ??}else if("double".equals(System.getProperty("precition"))){
    ???double d1 = Double.parseDouble(str1);
    ???double d2 = Double.parseDouble(str2);
    ???System.out.println ("d1"+"/"+"d2"+"="+divide(d1,d2));
    ??}else if("你好".equals(System.getProperty("precition"))){
    ???System.out.println ("你好");
    ??}
    ?
    ?
    ?}
    ??public static int divide(int i1,int i2){
    ???return i1/i2;
    ??}
    ??public static double divide(double d1,double d2){
    ???return d1/d2;
    ??}
    ---------------------------------------------------------------------------------猜數字游戲代碼
    class GuessGame{
    ?
    ?public static? void main(String[] args){
    ??outer:
    ??while(true){
    ????
    ????int num =1?+ (int)(Math.random()*100);
    ????int num1=20 ;
    ????System.out.println ("輸入數字"+num);
    ?????
    ????? ?inner:
    ????? ?while(num!=num1){
    ????? ??
    ????? ??java.io.BufferedReader in = new java.io.BufferedReader(
    ??????????new java.io.InputStreamReader(System.in));

    ????? ??try{
    ???????num1 = Integer.parseInt(in.readLine());
    ?????? ????if(num1>100 || num1<1){
    ????? ??? ??throw new java.lang.NumberFormatException();
    ????? ????}?
    ????? ????
    ???? ??}catch(java.io.IOException e){
    ????? ??? System.out.println ("io error"+e);
    ????? ??}catch(java.lang.NumberFormatException e2){
    ????? ???System.out.println ("請輸入正確的數字[1-100]");
    ????? ???continue ;
    ????? ??}
    ????? ???if(num>num1){
    ????? ????System.out.println ("is too small");
    ????? ???}else if(num<num1){
    ???? ????System.out.println ("is too large");
    ???? ???}else{
    ???? ????System.out.println ("ok");
    ???? ????
    ???? ????System.out.print ("還玩么? (y/n)");
    ???? ????
    ???? ?????try{
    ???? ??????if("y".equalsIgnoreCase(in.readLine())){
    ???? ???????continue outer;
    ???? ??????}
    ???? ?????}catch(java.io.IOException e){}
    ???? ???????break outer;
    ???? ???}
    ?????}

    ????}
    ??}?
    ??
    ??
    }
    ---------------------------------------------------------------------從隨機數據取出與輸入相等的數據

    static char[] getText(String s){
    ????int w = s.length();
    ????char[] cc =new char[w];
    ????
    ????int? index=0;
    ????while(true){
    ?????char? c = (char)(Math.random()*65536);
    ?????if(c==s.charAt(index)){
    ??????cc[index]=c;
    ??????index++;
    ??????if (index>=w){
    ???????break;
    ????????
    ??????}?
    ?????}
    ????}
    ???return cc;
    ??}
    -----------------------------------------------------------------------多維數組的賦值------

    ??int[][] in= new int[5][];
    ??in[0]? = new int[]{0,1,2,3};
    ??in[1] = new? int[]{1,2};
    --------------------------------------------------------覆蓋垃圾收集方法
    public void finalize(){
    ?System.out.println ("000");
    }
    -----------------------------------------------------移位)

    3>>1 正數移位 0011---》 0001? 為1(正數移位在前面加0)
    -3>>1 負數移位 1011 -》1100--》1101 移位得 1110 --》1101--》1010 為-2(負數移位在前面加1)
    -3>>>1? (這種移位以后再看???????????????未懂)
    -

    -----------描述注釋文檔----------------javadoc -d 文件絕對路徑 -author -version private/public/protected

    /**
    ?*
    ?*描述學生信息
    ?*@author 阮衛
    ?*@version 1.1
    ?*@docroot e:\lesson\day02\indexz
    ?*/

    /**
    *無參數據構造函數
    */

    /**
    * 有參數據構造函數
    *@param n? 表示姓名
    */

    /**
    *方法說明
    */
    -----------------------------------------------
    Integer.MIN_VALUE
    Short.MAX_VALUE
    -----------------------------------
    //在一常量池中引用的是同一地址
    ????q="sss";
    ????w="sss";

    posted on 2006-05-26 14:05 Javaphua 閱讀(359) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 免费无码又爽又刺激聊天APP| 中文在线观看国语高清免费| 黄色片在线免费观看| 久久亚洲精品成人| 国产精品免费看久久久| 亚洲人成人无码网www电影首页| 一级毛片免费不卡直观看| 精品国产日韩亚洲一区| 成人免费一区二区三区| 亚洲AV永久无码精品| 日韩精品无码专区免费播放| 亚洲系列国产精品制服丝袜第| 最近2019年免费中文字幕高清| 亚洲性色高清完整版在线观看| 97在线观免费视频观看| 亚洲爆乳AAA无码专区| 亚洲国产精品无码久久青草| 国产免费内射又粗又爽密桃视频| 亚洲av无码乱码国产精品| **毛片免费观看久久精品| 亚洲婷婷第一狠人综合精品| 蜜臀91精品国产免费观看| 一级毛片免费播放男男| 亚洲色图国产精品| 我想看一级毛片免费的| 农村寡妇一级毛片免费看视频| 亚洲熟妇无码AV在线播放| 亚洲黄色免费电影| 国产精品亚洲一区二区三区久久 | 国产一区二区免费| 亚洲视频小说图片| 日本免费一区尤物| a级毛片100部免费观看| 456亚洲人成影院在线观| 亚洲日本韩国在线| 黄+色+性+人免费| 国产高清视频免费在线观看 | 久久精品国产亚洲AV网站| 免费观看黄网站在线播放| 精品97国产免费人成视频| 77777午夜亚洲|