📄 gaamisc.java
字号:
import java.applet.*;
import java.net.*;
import java.io.*;
import java.text.*;
import lundin.SymbolicMath.*;
/*
import jfd.exp.SymbolTable;
import jfd.exp.Node;
import jfd.exp.ExpressionParser;
*/
public class GaaMisc {
public static GaaLog deb;
public static DecimalFormat gaaFormat= new DecimalFormat("#.###");
public static DecimalFormat f0 = new DecimalFormat("0");
public static DecimalFormat f02 = new DecimalFormat("00");
public static DecimalFormat f03 = new DecimalFormat("000");
public static DecimalFormat f04 = new DecimalFormat("0000");
public static DecimalFormat f05 = new DecimalFormat("00000");
public static DecimalFormat f06 = new DecimalFormat("000000");
public static DecimalFormat f1 = new DecimalFormat("0.0");
public static DecimalFormat f2 = new DecimalFormat("0.00");
public static DecimalFormat f3 = new DecimalFormat("0.000");
public static DecimalFormat f4 = new DecimalFormat("0.0000");
public static DecimalFormat f7 = new DecimalFormat("0.0000000");
public static boolean debugOn;
public static int debugMode;
public GaaMisc() {
debugOn = false;
debugMode = 0;
deb = new GaaLog("Gaa Log Window");
deb.hide();
deb.showMsg("");
deb.reshape(50,40,540,380);
deb.start();
}
public static boolean flip(double ref) {
double rand = (double) Math.random();
if (rand < ref)
return true;
else
return false;
}
public static int compareDouble(double x1,double x2){
int flag;
if (x1 < x2)
flag = -1;
else if (x1 > x2)
flag = 1;
else
flag = 0;
return flag;
}
public static double factorial(int n) {
double result = 1;
while (n > 1) {
result *= n;
--n;
}
return result;
}
public static String largeNumberFormat (double dbl, int mode) {
DecimalFormat num = new DecimalFormat();
Double d = new Double(dbl);
String txtScientific = " " + d.doubleValue();
String txtDecimal = " " + num.format(d.doubleValue());
if (mode == 1)
return txtScientific;
else
return txtDecimal;
}
public static String formatDouble(double num, int places) {
String st = "", temp = "";
int pos;
try {
temp = String.valueOf(num);
pos = temp.indexOf('.');
st = temp.substring(0,pos+places+1);
}
catch (Exception e) {
st = temp;
//deb.debug("GaaMisc formatDouble error: " + e.toString());
}
return(st);
}
public static String getTextFromFile(URL fileURL) {
DataInputStream inData;
boolean eof = false;
String line = "";
String txt = "";
InputStream in;
/*
try {
fileURL = new URL("file:///G:/Java/Projects/Gaa/GaaHelp.txt");
}
catch(Exception eee) {
};
*/
try {
in = fileURL.openStream();
inData = new DataInputStream(in);
}
catch(IOException e) {
return("");
}
while ((!eof) && (line != null)) {
try {
line = inData.readLine();
if (line != null) {
txt = txt + line +"\n";
}
}
catch(Exception e) {
}
}
return txt;
}
public static double evalFormula(String formula, String params) {
Eval ev = new Eval();
double ans = Double.NaN;
try{
ans = ev.eval(formula,params);
}
catch (Exception ex) {
ans = 1234.5678;
deb.debug("evalFormula error: "+ex.toString());
}
return(ans);
}
/*
public static double evalString(String formula) {
double result = 8765.4321;
SymbolTable table = new SymbolTable(true);
try
{
Node n = ExpressionParser.parse(formula);
if(n != null)
result = n.execute(table);
}
catch(Exception e)
{
result = -1234.5678;
}
return result;
}
*/
public static double evalStringJel(String formula, double vars[]) {
double d;
d = JelProcs.calc(formula,vars);
return d;
}
public static void dbg(String txt) {
try {
GaaAction.deb.debug(txt);
}
catch (Exception e) {
}
}
public static void dbg(String txt, boolean flag) {
if (flag) {
dbg(txt);
}
}
public static void debug(String txt) {
if (debugOn)
System.out.println(txt);
}
public static void debug(String txt, int mode) {
if (mode == 1)
System.out.println(txt);
else if (mode == 2)
dbg(txt);
else if (mode == 3) {
System.out.println(txt);
dbg(txt);
}
}
public static boolean stringToBoolean(String txt) {
String trues = "onOnONtrueTrueTRUEyesYesYes";
int index = trues.indexOf(txt);
if (index == -1)
return(false);
else
return(true);
}
public static String booleanToString(boolean flag) {
if (flag)
return("True");
else
return("False");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -