Outils pour utilisateurs

Outils du site


informatique:java:tips

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
informatique:java:tips [14/02/2011 15:55] – créée cyrilleinformatique:java:tips [16/06/2023 10:02] (Version actuelle) – [Swing] cyrille
Ligne 1: Ligne 1:
 ====== Java Tips ====== ====== Java Tips ======
  
-Swing UI:+Plein de choses interressantes dans le livre "Killer Game Programming in Java". Des extraits de chapitres et de codes[[http://fivedots.coe.psu.ac.th/~ad/jg/index.html]]. 
 + 
 +http://filthyrichclients.org/ Le bouquin de Romain Guy & Chet Haase. In Filthy Rich Clients, we explain how to create filthy rich effects in your applications, from the fundamental graphics, GUI, and animation technology up through sample code and algorithms for the effects themselves. Des exemples de code. 
 + 
 +[[http://zetcode.com/tutorials/javagamestutorial/|Java 2D games tutorial]] 
 +===== Swing ===== 
   * [[http://download.oracle.com/javase/tutorial/uiswing/components/table.html|How to Use Swing JTables]] (binding, cell editors, ...)   * [[http://download.oracle.com/javase/tutorial/uiswing/components/table.html|How to Use Swing JTables]] (binding, cell editors, ...)
 +  * About [[/informatique/java/tips/Drag & Drop|Drag & Drop]]
 +  * Plein d'effets visuels avec Swing par Romain Guy: <del>[[http://jroller.com/gfx/page/Archives]]</del>
 +===== CVS Format =====
 +
 +  * [[http://opencsv.sourceforge.net/]]: opencsv is a very simple csv (comma-separated values) parser library for Java. It was developed because all of current csv parsers I've come across don't have commercial-friendly licenses.
 +
 +===== Read input from console =====
 +
 +Read console input using **java.io.Console** instance - //Don't work in Eclipse IDE//.
 +<code java>
 +private static void usingConsoleReader()
 +{
 +  Console  console = System.console();
 +  if (console != null)
 +  {
 +     String inputString = console.readLine("Name: ");
 +     System.out.println("Name entered : " + inputString);
 +  }
 +}
 +</code>
 +
 +Read console input using **BufferedReader** instance
 +<code java>
 +private static void usingBufferedReader()
 +{
 +  BufferedReader bufferRead = new BufferedReader( new InputStreamReader( System.in ) );
 +  String inputString = bufferRead.readLine();
 +  System.out.println( inputString );
 +}
 +</code>
 +
 +Read console input using **Scanner** instance
 +<code java>
 +private static void usingScanner()
 +{
 +  Scanner scanIn = new Scanner( System.in );
 +  String inputString = scanIn.nextLine();
 +  scanIn.close();           
 +  System.out.println(inputString);
 +}
 +</code>
 +
 +===== Process Input Stream Reader =====
 +
 +<code java>
 +import java.io.BufferedReader;
 +import java.io.IOException;
 +import java.io.InputStream;
 +import java.io.InputStreamReader;
 +import java.net.InetAddress;
 +import java.net.UnknownHostException;
 +import java.io.*;
 + 
 +public class Traceroute {
 + public static void main(String[] args){
 +  Runtime t = Runtime.getRuntime();
 +  try {
 +   Process p = t.exec("traceroute  "+args[0]);
 +   //Process p = t.exec("ping -w 1 "+args[0]);
 +   InputStream i = p.getInputStream();
 +   InputStreamReader r = new InputStreamReader(i);
 +   BufferedReader re = new BufferedReader(r);
 +   int m =0;
 +   while(true){
 +    String content = re.readLine();
 +    System.out.println(content);
 +    if(content == null){
 +     break;
 +    }
 +   }
 +   re.close();
 +   r.close();
 +  } catch (IOException e) {
 +    e.printStackTrace();
 +  }
 + }
 +}
 +
 +</code>
 +
 +===== Convert a Java OutputStream to an InputStream =====
 +
 +[[http://ostermiller.org/convert_java_outputstream_inputstream.html]]
 +
 +Method 1: Buffer the data using a byte array
 +<code java>
 +  ByteArrayOutputStream out = new ByteArrayOutputStream();
 +  class1.putDataOnOutputStream(out);
 +  class2.processDataFromInputStream(
 +    new ByteArrayInputStream(out.toByteArray())
 +  );
 +</code>
 +Method 2: Use pipes
 +<code java>
 +PipedInputStream in = new PipedInputStream();
 +  PipedOutputStream out = new PipedOutputStream(in);
 +  new Thread(
 +    new Runnable(){
 +      public void run(){
 +        class1.putDataOnOutputStream(out);
 +      }
 +    }
 +  ).start();
 +  class2.processDataFromInputStream(in);
 +</code>
 +Method 3: Use [[http://ostermiller.org/utils/CircularBuffer.html|Circular Buffers]]
 +<code java>
 +  // Multiple Threaded Example of a Circular Buffer
 +
 +  CircularByteBuffer cbb = new CircularByteBuffer();
 +  new Thread(
 +    new Runnable(){
 +      public void run(){
 +        class1.putDataOnOutputStream(cbb.getOutputStream());
 +      }
 +    }
 +  ).start();
 +  class2.processDataFromInputStream(cbb.getInputStream());
 +</code>
 +<code java>
 +  // Single Threaded Example of a Circular Buffer
 +
 +  // buffer all data in a circular buffer of infinite size
 +  CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE);
 +  class1.putDataOnOutputStream(cbb.getOutputStream());
 +  class2.processDataFromInputStream(cbb.getInputStream());
 +</code>
 +
 +===== Serial communication =====
 +
 +Communication série avec Java
 +
 +  * http://www.java-samples.com/showtutorial.php?tutorialid=11
 +  * http://christophej.developpez.com/tutoriel/java/javacomm/
 +
 +
 +
informatique/java/tips.1297695343.txt.gz · Dernière modification : 19/05/2012 00:15 (modification externe)

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki