Java Plugins@Firefox

為了要作統計物理方面的資訊整理,在很多的物理網頁上都有JavaApplet的Ising Model示範,所以就需要在Firefox上安裝Java的plugin,按照下列方式來安裝:

samuel@pika046:plugins$ file /home/samuel/jdk1.5.0_06/jre/plugin/i386/ns7/libjavaplugin_oji.so


 

File Manipulation

Java來進行檔案的讀取
java.lang.String strFileName=args[0];
java.io.File objFile=new java.io.File(strFileName);;
java.io.FileReader objFileReader;
char[] chrBuffer = new char[10];
int intLength;

if(objFile.exists())
 { objFileReader = new java.io.FileReader(objFile);
 while((intLength=objFileReader.read(chrBuffer))!=-1){ out.write(chrBuffer,0,intLength); }
 objFileReader.close(); }
 out.println("File not existed: "+strFileName); }

String nameOfTextFile = "/usr/anil/imp.txt";
try
 { PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
 pw.println(str);
 pw.close(); }
catch(IOException e) { out.println(e.getMessage()); }

 

RegExp@Java

對於Regular Expression,可在$JavaDoc/api/java/util/Scanner.html中略知。 A simple text scanner which can parse primitive types and strings using regular expressions. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.
import java.util.Scanner;
String input = "1 fish 2 fish red fish blue fish";
Scanner s = new Scanner(input);
s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
MatchResult result = s.match();
for (int i=1; i<=result.groupCount(); i++) System.out.println(result.group(i);
s.close();
Scanner的物件可以用findInLine(RegExp)來比對字串,然後利用match傳回RegExp物件,再利用此RegExp物件的group找出所要的字串,很類似python的作法。 The default whitespace delimiter used by a scanner is as recognized by Character.isWhitespace. The findInLine(java.lang.String), findWithinHorizon(java.lang.String, int), and skip(java.util.regex.Pattern) methods operate independently of the delimiter pattern. These methods will attempt to match the specified pattern with no regard to delimiters in the input and thus can be used in special circumstances where delimiters are not relevant. These methods may block waiting for more input.
 

Swing Tutorial

Swing Tutorial來瞭解java中,如何快速地作出GUI應用程式。
  1. http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/
  2. Components
  3. NTU Swing介紹
  4. zaiane AWT Swing介紹
  5. JFormDesigner
  6. JFrameBuilder
  7. Form Designer
  8. GUI Builder
import javax.swing.*;
public void main(String[] args)
 { JFrame.setDefaultLookAndFeelDecorated(true);
 JFrame Frame=new JFrame("Hellow the Java Wonderland World");
 JLabel Label =new JLabel("Hello Bravo World");
 Frame.getContentPane.add(Label);
 Frame.getContentPane().setLayout(new FlowLayout());
 Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 Frame.pack();
 Frame.setVisible(true); }
Each JRootPane contains several components referred to here by variable name: glassPane (a JPanel by default), layeredPane (a JLayeredPanel), contentPane (a JPanel by default) and menuBar (a JMenuBar).

JRootPane包括GlassPane, LayeredPane, ContentPane, MenuBar。GlassPane好像是放在LayeredPane上一個透明的Pane,對於攔截Mouse events,或是重導應用程式的焦點特別有用,可用
setGlassPane(myComponent); getGlassPane().setVisible(true);
來使用它。

 JMenuBar menu = new JMenuBar();
 setJMenuBar(menu);
 setContentPane(myComponent);
The default layout for the contentPane is BorderLayout. The default layout for any other JPanel is FlowLayout. Be careful not to set the layout of a JFrame directly. This will generate an exception. Setting the layout of the rootPane is also something that should be avoided because every JRootPane uses its own custom layout manager called RootLayout.
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
WindowListener l = new WindowAdapter()
 { public void windowClosing(WindowEvent e){ System.exit(0); } };
myJFrame.addWindowListener(l);
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
class BorderTest extends JFrame
 { public BorderTest()
  { setTitle("Border Test");
  setSize(450, 450);
  JPanel content = (JPanel) getContentPane(); 
  content.setLayout(new GridLayout(6,2));
  JPanel p = new JPanel();
  p.setBorder(new BevelBorder (BevelBorder.RAISED));
  p.add(new JLabel("RAISED BevelBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new BevelBorder (BevelBorder.LOWERED));
  p.add(new JLabel("LOWERED BevelBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new LineBorder (Color.black, 5));
  p.add(new JLabel("Black LineBorder, thickness = 5"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new EmptyBorder (10,10,10,10));
  p.add(new JLabel("EmptyBorder with thickness of 10"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new EtchedBorder (EtchedBorder.RAISED));
  p.add(new JLabel("RAISED EtchedBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new EtchedBorder (EtchedBorder.LOWERED));
  p.add(new JLabel("LOWERED EtchedBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new SoftBevelBorder (SoftBevelBorder.RAISED));
  p.add(new JLabel("RAISED SoftBevelBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new SoftBevelBorder (SoftBevelBorder.LOWERED));
  p.add(new JLabel("LOWERED SoftBevelBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new MatteBorder (new ImageIcon("spiral.gif")));
  p.add(new JLabel("MatteBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new TitledBorder ( new MatteBorder (new ImageIcon("spiral.gif")), "Title String"));
  p.add(new JLabel("TitledBorder using MatteBorder"));
  content.add(p);

  p = new JPanel();
  p.setBorder(new TitledBorder ( new LineBorder (Color.black, 5), "Title String"));
  p.add(new JLabel("TitledBorder using LineBorder"));
  content.add(p);
  p = new JPanel();
  p.setBorder(new TitledBorder ( new EmptyBorder (10,10,10,10), "Title String"));
  p.add(new JLabel("TitledBorder using EmptyBorder"));
  content.add(p);
  setVisible(true); }
   public static void main(String args[]) { new BorderTest(); } }

 

Java getopt

http://www.urbanophile.com/arenn/hacking/download.html
 

Java Tutorial

  1. http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
  2. Java Links
  3. jdk-5.0 chm
  4. The lightweight Java IDE
  5. java class簡介
public class ForEachDemo
        { public static void main(String[] args)
                { int[] arrayOfInts = { 32, 87, 3, 589, 12, 1076, 2000, 8, 622, 127 };
                for (int element : arrayOfInts) { System.out.print(element + " "); }
                System.out.println(); } }

This page is powered by Blogger. Isn't yours?