import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class StringParser { private String data; private String delimiter; public StringParser() { } public StringParser(String data, String delimiter) { this.data = data; this.delimiter = delimiter; } public ListgetListToken() { List tokens = new ArrayList (); StringTokenizer tokenizer = new StringTokenizer(data, delimiter); while (tokenizer.hasMoreTokens()) { tokens.add(tokenizer.nextToken()); } return tokens; } public String getData() { return data; } public void setData(String data) { this.data = data; } public String getDelimiter() { return delimiter; } public void setDelimiter(String delimiter) { this.delimiter = delimiter; } }
StringParser String tokenizer and parser
Maximize JFrame
Posted by
tediscript
at
12:38 PM
|
Put this code in JFrame constructor
setExtendedState(getExtendedState() | javax.swing.JFrame.MAXIMIZED_BOTH);
List available port in Java
Posted by
tediscript
at
12:34 PM
|
import javax.comm.*; import java.util.Enumeration; public class ListPorts { public static void main(String args[]) { Enumeration ports = CommPortIdentifier.getPortIdentifiers(); while (ports.hasMoreElements()) { CommPortIdentifier port = (CommPortIdentifier) ports.nextElement(); String type; switch (port.getPortType()) { case CommPortIdentifier.PORT_PARALLEL: type = "Parallel"; break; case CommPortIdentifier.PORT_SERIAL: type = "Serial"; break; default: type = "Unknown"; break; } System.out.println(port.getName() + ": " + type); } } }
Property Factory to save configuration in file config
Posted by
tediscript
at
12:32 PM
|
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PropertyFactory {
public static void save(Properties p, String fileName, String comment) {
PrintWriter pw = null;
try {
pw = new PrintWriter(fileName);
} catch (FileNotFoundException ex) {
}
try {
p.store(pw, comment);
} catch (IOException ex) {
}
}
public static Properties read(String fileName) {
Properties p = new Properties();
Reader r = null;
try {
r = new FileReader(fileName);
} catch (FileNotFoundException ex) {
}
try {
p.load(r);
} catch (IOException ex) {
}
return p;
}
}
Java Default System Look and Feel
Posted by
tediscript
at
11:31 AM
|
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
ex.printStackTrace();
}
Subscribe to:
Posts (Atom)