Frequently Used Java Commands
February 5, 2019
Native Java Documentation
Integer
String str = [Link](iValue);
int iValue = ([Link](str)).intValue();
Double
String str = [Link](dValue);
double dValue = ([Link](str)).doubleValue();
String
Index Numbers
abcdefgh
012345678
String substr = [Link](iBegin,iEnd);
[Link](2,5) = cde
int indexMatch = [Link](strFind);
[Link](”c”) = 2
int indexMatch = [Link](strFind);
int iLength = [Link]();
boolean bMatch = [Link](strCompare);
Arrays
int iLength = [Link];
ClassName[] classArray = new ClassName[nClasses];
classArray[0] = new ClassName();
classArray[1] = new ClassName();
int[] iArray = new int[nLocs];
int[] iArray = {0,1,2};
int[][] iMatrix = new int[nLocsFirst][];
iMatrix[0] = new int[nLocs0];
iMatrix[1] = new int[nLocs1];
For Each
int[] iArray;
for (int iElement : iArray) {
[Link](iElement);
}
2
Vector
Vector<Class> vec = new Vector<Class>(); Class: String, Integer , etc
int iLocs = [Link]();
[Link]();
[Link](str);
String str = (String)[Link](iLocation);
[Link](new Integer(iValue));
int iValue = ((Integer)([Link](iLocation))).intValue();
ClassName c = new ClassName();
[Link](c);
ClassName c = (ClassName)([Link](iLocation));
Parameterizing Raw to Generic Type
Vector<String> vecName = new Vector<String>();
JList<String> listName = new JList<String>();
List of Files
File f = new File(strDirectoryPath);
String[] strList = [Link](); // Includes all files in directory
String[] strList = [Link](new MyFilter); // Includes only “filtered” files
import [Link];
class MyFilter implements FilenameFilter {
public boolean accept(File fDirectory, String strFilename) {
if(…) return true;
return false;
}
}
WWW File Names
String strFileName = “[Link]
Font ([Link])
Font fontNew = new Font(strFontName, iFontStyle, iSize)
strFontName = [Link], [Link], [Link], Font.SANS_SERIF, …
iFontStyle = [Link], [Link], [Link], …
Exceptions
Throw(new Exception(“Exception message.”));
String strMessage = [Link]();
Focus
[Link]();
Unicode Characters
char cUnicode = 0x00A9 // 00A9 is the Unicode copyright symbol
Colors
Color colorNew = new Color(0xFF0000) // FF0000 is the red hex spec
3
JDialog – Modal Mode
Calling routine
Dialog jDialog = new Dialog();
[Link]();
[Link]();
Dialog
Constructor
[Link](true); // Don’t return until setVisible(false)
[Link](true);
getInformation();
.
.
return information;
JList
JList<Class> list = new JList<Class>(); Class: String, Integer, …
[Link](Object[]);
[Link](Vector);
[Link](new Vector()) // clears list
[Link](iRows);
[Link](iIndex);
[Link](“Value”), true); // true allows scrolling
int iIndex = [Link]();
str strEntry = (String)[Link](); // null if none selected
boolean3sum = ([Link]()).getSize();
str strIndex = (String)([Link]()).getElementAt(iIndex);
JComboBox
JComboBox<Class> list = new JComboBox<Class>(); Class: String, Integer, …
[Link](iValue);
[Link](iIndex)
[Link]()
[Link](str);
[Link](str);
str = (String) [Link]();
Unicode
char cUnicode = 0x____;
Tuples
See [Link].
4
JProgressBar
private void startTask() { // Call by the action button or whatever
// Set progress bar parameters
[Link](100);
[Link](0);
[Link](true); // Print text or percent completed
TaskInnerClass task = new TaskInnerClass();
textPane = new JTextPaneOutput(scrollPane_1);
[Link]();
}
class TaskInnerClass extends Thread {
public void run() {
[Link](true);
runTask();
[Link](false);
}
}
private void runTask() {
[Link](iIteration)
[Link](str); // Print str rather than percent completed
// Do the work
}
JFileChooserFilters
[Link](new SpecialFileFilter());
class MySpecialFileFilter extends [Link] {
public String getDescription() {
return "Special files(*.*)";
}
public boolean accept(File f) {
String str = [Link]();
if([Link]("~") < 0) return true;
return false;
}
Catching Key Strokes
public void jListPlayers_keyReleased(KeyEvent e) {
int iKeyCode = [Link]();
if(iKeyCode == KeyEvent.VK_UP || iKeyCode == KeyEvent.VK_DOWN) {
}
}
ButtonGroup
ButtonGroup bg = new ButtonGroup();
[Link](jButton);
In Eclipse: Right click on button in the design window.
Scrolling
Swing Containers: JScrollPane
Put component in the JScrollPane
5
Callbacks
// Specific method calls a general purpose method
// General purpose method needs info that is specific to the specific class
interface CallBackInterface {
public xxxx interfaceMethod(…); // “Placemark” for interface method
}
class InterfaceSpecificClass implements CallBackInterface { // MainClass
// Define interface method that provides interface info that is specific to this class
public xxxx interfaceMethod(…) {
// Code that is called by calling class
.
.
.
return vbl;
}
public specificMethodThatCallsGeneralPurposeMethod(…) {
GeneralPurposeClass generalPurposeClass = new GeneralPurposeClass(…);
[Link](this, …);
}
}
class GeneralPurposeClass {
public xxxx generalPurposeMethod (CallBackInterface cbi, …) {
xxxx vbl = [Link](); // Get vbl info from interfaceMethod()
.
.
.
}
}
Interfaces
// Interface file
public interface InterfaceName
{
public xxxx interfaceMethod(…); // “Placeholder” for interface method
}
// The root class calls the interface method either in ClassToBeCallled1 or ClassToBeCalled2
Class RootClass
InterfaceName inter = new ClassToBeCalled1 or ClassToBeCalled2
[Link](…);
Class ClassToBeCalled1 implements InferfaceName
public xxxx interfaceMethod(…) // Operative version of interface method
{
..
.
}
Class ClassToBeCalled2 implements InferfaceName
public xxxx interfaceMethod(…) // Operative version of interface method
{
..
.
}
6
Abstract Classes
class CallingClass {
ClassAbstract classabs;
classabs = new ClassGeneric1();
or
classabs = new ClassGeneric2();
[Link]()
public abstract class ClassAbstract {
abstract xxxs method();
}
public class ClassGeneric1 extends ClassAbstract {
public xxxx method() {
}
}
public class ClassGeneric2 extends ClassAbstract {
public xxxx method() {
}
}
Inner and Static Nested Classes
TestMainClass testMainClass = new TestMainClass();
[Link] testInnerClass = [Link] TestInnerClass();
[Link]([Link]());
[Link]([Link]());
public class TestMainClass {
public class TestInnerClass {
public String subroutine() {
return "TestInnerClass: subroutine()";
}
public static class TestStaticNestedClass {
public static String subroutine() {
return "TestStaticNestedClass: subroutine()";
}
}
}
7
System
[Link](str);
[Link](str);
[Link](str)
[Link] Java Runtime Environment version
[Link] Java Runtime Environment vendor
[Link] Java vendor URL
[Link] Java installation directory
[Link] Java Virtual Machine specification version
[Link] Java Virtual Machine specification vendor
[Link] Java Virtual Machine specification name
[Link] Java Virtual Machine implementation version
[Link] Java Virtual Machine implementation vendor
[Link] Java Virtual Machine implementation name
[Link] Java Runtime Environment specification version
[Link] Java Runtime Environment specification vendor
[Link] Java Runtime Environment specification name
[Link] Java class format version number
[Link] Java class path
[Link] List of paths to search when loading libraries
[Link] Default temp file path
[Link] Name of JIT compiler to use
[Link] Path of extension directory or directories
[Link] Operating system name
[Link] Operating system architecture
[Link] Operating system version
[Link] File separator ("/" on UNIX)
[Link] Path separator (":" on UNIX)
[Link] Line separator ("\n" on UNIX)
[Link] User's account name
[Link] User's home directory
[Link] User's current working directory
Terminating a Process
[Link](iErrorCode) // Typically, iErrorCode = 0.
8
FW Library Documentation
(FW) ConvertString
String[] [Link](str, strDelimiter);
int[] [Link](str, strDelimiter);
double[] [Link](str, strDelimiter);
boolean[] [Link](str, strDelimiter); // strDelimiter: add + to eliminate empty cells
double[] [Link](str[]);
double [Link](str);
String [Link](str);
String [Link](str, iBegin, iEnd)
String [Link](str[], strOld, strNew);
String [Link](str, strOld, strNew);
(FW) ConvertStringToArray
String[] [Link](strSource);
String[] [Link](strSource, strDelimitor);
int[] [Link](strSource);
int[] [Link](strSource, strDelimitor);
double[] [Link](strSource);
double[] [Link](strSource, strDelimitor);
(FW) FormattedOutput
String [Link](iValue [,strAllign, iLength]);
String [Link](dValue, iLength);
String [Link](dValue, strAllign, iLength, iDecimals);
String [Link](iBlanks);
String [Link](str);
String [Link](dValue [,strAllign, iLength]);
(FW) JavaMail
JavaMail(strMailServer, strSender, strAddressee, strMessage) throws Exception
boolean isMailOK();
(FW) Clipboard
[Link](this, str);
String [Link](this);
(FW) JWindowUtility
[Link](parentWindow, window);
[Link](window);
[Link](window);
boolean [Link](jComponent, bWidth, bHeight);
String [Link](strDirectory);
String [Link]();
String [Link](strModule, strVersion, strFilename);
String [Link](strModule, strVersion);
9
(FW) DateTimeAux
long lTime = [Link](); // Get current time
long lTime = [Link](lMilliSeconds);
long lTime = [Link](iYear, iMonth, iDay, iHour, iMinute, iSecond) ;
str = [Link](lMilliSeconds);
str = [Link](lMilliSeconds, strSeparator);
str = [Link](lMilliSeconds);
str = [Link](lMilliSeconds, strSeparator);
int[] = [Link](lMilliSeconds);
int[] = [Link](lMilliSeconds);
int = [Link](lMilliSeconds);
(FW) Sorters
void [Link](strArray);
void [Link](iArray);
void [Link](lArray);
void [Link](dArray);
void [Link](iLength, strArray);
void [Link](iLength, iArray);
void [Link](iLength, lArray);
void [Link](iLength, dArray);
int[] [Link](strArray);
int[] [Link](iArray);
int[] [Link](lArray);
int[] [Link](dArray);
int[] [Link](iLength, strArray);
int[] [Link](iLength, iArray);
int[] [Link](iLength, lArray);
int[] [Link](iLength, dArray);
(FW) Html Utilities
String [Link](String str);
String [Link](String strTable);
String [Link](FileAsciiRead far, String strStart, String strStop);
strStart = “FirstStartString`SecondStartString`_”); _ indicates a line skip
strEnd = “FirstStopString`SecondStopString`_”); _ indicates a line skip
strEnd = “”; return immediately
NB: If only one start and stop string no grave accenst are needed.
String [Link](String str);
(FW) JQueryBox
JQueryBox qb = new JQueryBox(strTitle, strMessage, strLabel);
JQueryBox qb = new JQueryBox(strTitle, strMessage, strLabelArray);
[Link](strLabel);
[Link]();
10
(FW) Running a Jar File
[Link](strJarPath, bParentWait, bParentDispose);
(FW) Copy a File from the Web
JWebCopyUtility webCopy = new JWebCopyUtility(null, progressBar);
webCopy(strWebPath, strPCPath, strFileNameExt);
[Link](true);
(FW) Directory History
JDirectoryHistory dh = new JDirectoryHistory(strDirectoryHistoryFilename);
For example, JDirectoryHistory dh = new JDirectoryHistory(“Econ55);
This is a text file that is in the My documents directory My Histories
DirectoryHistory dh = new DirectoryHistory(strDirectoryHistoryFilename);
String strLastDirectory = [Link]();
strLastDirectory ends with a back slash, \.
[Link](jchooser);
public void this_windowClosing(WindowEvent e) {
[Link](jchooser);
}
[Link](strFileDirectory);
(FW) JTextPaneOutput
JtextPaneOutput jTextPane = new JtextPaneOutput(jScrollPane);
[Link](str);
[Link](str);
[Link]();
[Link](c);
[Link](bool);
[Link](bool);
[Link](bool);
[Link](str); // Serif, Sansserif, Monospace, Dialog
[Link](int);
[Link](bool);
[Link](bool)
[Link](int);
[Link](int[]);
[Link](int[], strAlign[]); // strAlign “l”, “r”, “c”, “d”
[Link](int)
[Link](strAlign); // strAlign “l”, “r”, “c”, “d”
11
(FW) JGraph
JGraph graph = new JGraph(label, strAxisRange, strAxisNames, strAxisNumericalLabels);
strAxisRange = XMin YMin XMax YMax [XLabelDisplayFactor YLabelDisplayFactor]
strAxisNames = “XName YName”;
strAxisNumericalLabels = “ T/F T/F”;
JGraph graph = new JGraph(label, strAxisRange);
drawAxes();
setPointDiameter(iPointDiameter) // 8 is a good value
setPointColor(color);
drawPoint(dX, dY, iPointDiameter, color, strSpec);
strSpec
X: draw line from point to x-axis
Y: draw line from point to y-axis
R: draw line from point to the extreme right of graph
U: draw line from point the top of graph
drawPoint(dX, dY [, iPointDiameter, color]);
drawPoint(dXYs[] [, iPointDiameter, color]);
setLineWidth(iLineWidth) // 1 is the default
drawLine(dX0, dY0, dX1, dY1 [, iLineWidth, color]);
drawLine(dX, dY, dSlope [, iLineWidth, color]);
drawLine(dXYs[][] [, iPointDiameter, color]);
drawLineEquation(dCoefX, dCoefY, dConst [, iLineWidth, color]);
drawCurve(CurveInterface curveInterface, dXMin, dXMax, dXIncrement);
drawCurve(CurveInterface curveInterface, dXMin, dXMax [, iLineWidth, color]);
drawPolygon(dXs[], dYs[] [, iLineWidth, color]);
fillPolygon(dXs[], dYs[] [, color]);
setFontName(strFontName);
setFontColor(color);
setFontSize(iFontSize);
drawString(str, dX, dY, cPosition [, iFontSize, color]);
cPosition
U or ^: above and center horizontally
D or _: below and center horizontally
L or <: left and center vertically
R or >: right and center vertically
blank: right and no centering
getStringHeight(str);
getStringWidth(str);
double[] getMouseXYCoordinates();
Use WindowBuilder to add a motion listener to graph label;
then add call to getMouseXYCoordinates() to get mouse coordinates:
[Link](new MouseMotionAdapter() {
@Override
public void mouseXXXX(MouseEvent e) { // XXXX: Dragged, Pressed, …
dMouseXYCoordinates = [Link]();
}
});
12
(FW) Draw Curve Example
class XXXXProcessResults implements CurveInterface { // MainClass
public drawGraph(…) {
drawCurve(this, dXAxisMin, dXAxisMax [, iLineWidth, color]);
}
public double calCurveYFromX(double dX) {
// Calculate dY;
return dY;
}
}
(FW) JarUtility – Static routine
void [Link](strPath, bParentWait)
(FW) JWebCopyUtility
JWebCopyUtility(progressbar)
copyFile(strUrlPath, strPCPath)
13
(FW) File Utilities
boolean isOSMac()
boolean isOSWindows()
String getDocumentsPath()
String getDocumentsPath(strDirectory)
String correctFileSeparator(strFilePath)
String documentsPath(strDocDir, strFileName, strFileExt)
String documentsPath(strDocDir, strFileNameExt)
String documentsPath(strDocDirFileNameExt)
String webPath(strHttpDir, strFileName, strFileExt)
String webPath(strHttpDir, strFileNameExt)
String webPath(strHttpDirFileNameExt)
String genericPath(strFullDir, strFileName, strFileExt)
String genericPath(strFullDir, strFileNameExt)
String[] getFileDirectoryNameExtension(strFilePath)
String getFileDirectory(strFilePath)
String getFileName(strFilePath)
String getFileExtension(strFilePath)
boolean existsFile(strFilePath)
boolean existsDirectory(strDirectoryPath)
long lastModified(strFilePath)
void setLastModified(strFilePath, lDate)
boolean renameFile(strFilePathInput, strFilePathOutput)
boolean deleteFile(strFilePath)
void copyFile(strFilePathInput, strFilePathOutput) throws Exception
void copyFile(strFilePathInput, strFilePathOutput, lBufferMax) throws Exception
boolean createDirectory(strDirectory)
boolean removeDirectoryTree(strDirectory)
boolean removeDirectory(strDirectory)
String[] getListOfFiles(strDirectory)
String[] getListOfDirectories(strDirectory)
String stripAndAppendSeparator(str)
String appendSeparator(str)
String stripSeparator(str)
String abbreviateFilePathName(strFilePathName)
14
(FW) Ascii File Read (Both Applications and Applets)
try {
FileAsciiRead far = new FileAsciiRead(strFilePath);
String str;
while( (str = [Link]()) != null) {
// process
}
[Link]();
}
catch (Exception e) {
String str = [Link]() ;
}
(FW) Ascii File Write (Both Applications and Applets)
try {
FileAsciiWrite faw = new FileAsciiWrite (strFileName);
[Link](str);
[Link]();
[Link]();
}
(FW) Object File Read (Both Applications and Applets)
try {
FileObjectRead for = new FileObjectRead(strFileName);
double[] dVector = (double[])[Link]();
String[][] strArray = (String[][])[Link]();
}
(FW) Object File Write (Both Applications and Applets)
try {
FileObjectWrite fow = new FileObjectWrite(strFileName);
double[] dVector;
[Link](dVector);
String[][] strArray;
[Link](String[][]);
[Link]();
[Link]();
}
15
(FW) Random Access File Read (Applications Only)
try {
FileRandomRead frr = new FileRandomRead(strFileName);
Long lPointer = [Link]();
[Link](lPointer);
int iValue = [Link]();
double dValue = [Link]();
byte[] bArray = new byte[nLocs];
[Link](bArray);
String str = [Link]();
boolean bValue = [Link]();
}
(FW) Random Access File Write (Applications Only)
try {
FileRandomReadWrite frrw = new FileRandomReadWrite(strFileName);
Long lPointer = [Link]();
[Link](lPointer);
[Link](iValue);
[Link](dValue);
[Link](bArray);
[Link](str)
[Link](bValue);
}
16
(FW) JFileChooserCheckApplication1
JFileChooserCheckApplication fcca = new JFileChooserCheckApplication();
JFileChooserCheckApplication fcca = new JFileChooserCheckApplication(strExtension);
JFileChooserCheckApplication fcca = new JFileChooserCheckApplication(strExtensionArray);
String [Link](bMustExist); // Null if no file selected
Must be called to activate.
[Link](b);
String[] = [Link](b); // [Link] = 0 if no file selected
String [Link]();
String [Link](strTitle);
boolean [Link]();
(FW) JFileChooserCheckApplet
JFileChooserCheckApplet fcca =
new JFileChooserCheckApplet(strWebLocation, strDirectoryFileName);
strWebLocation = [Link]
strDirectoryFileName:
Description for File 1 [Link]
Description for File 2 [Link]
String [Link](bMustExist); // Null if no file selected
Must be called to activate.
String [Link]();
String [Link](strTitle);
boolean [Link]();
Using (FW) JFileChooserCheckInterface for Applications or Applets
facca = new JFileChooserCheckApplication(…) or JFilechooserCheckApplet(…)
MyClass myClass = MyClass(facc)
1
Swing: (FW) JFileChooserCheck (Used by JFileChooserApplication)
JFileChooserCheck fcc = new JFileChooserCheck();
JFileChooserCheck fcc = new JFileChooserCheck(bMustExist);
JFileChooserCheck fcc = new JFileChooserCheck(bMustExist, strExtension);
JFileChooserCheck fcc = new JFileChooserCheck(bMustExist, strExtensionArray);
[Link](strTitle);
[Link](strExtension);
[Link](strExtensionArray);
[Link](bMustExist);
[Link](true/false);
File [Link](); // Null if no file selected
Must be called.
String [Link]();
String [Link]();
String [Link]();
String [Link]();
17
(FW) JSpreadSheet
Column and Row Notation
strColumnNames[0] strColumnNames[1] strColumnNames[2] …
strArray[0][0] strArray[0][1] strArray[0][2] …
strArray[1][0] strArray[1][1] strArray[1][2] …
strArray[2][0] strArray[2][1] strArray[2][2] …
If there are row names, the first strArray column, strArray[i][0], contains the names.
Class MyParentFrame implements JSpreadSheetInterface
First, create a JScrollPane.
Constructors: Two types – one for separate column names and array and one for entire spreadsheet
JSpreadSheet ss =
// Separate column names and data
JSpreadSheet(this, JScrollPane scrollPane, String[][] strArray, String[] strColumnNames,
boolean bLockFirstColumn, boolean[][] bCellEditable)
JSpreadSheet(this, JScrollPane scrollPane, String[][] strArray, String[] strColumnNames,
boolean bLockFirstColumn)
// NB: All strArray cells will be editable.
JSpreadSheet(this, JScrollPane scrollPane, String[][] strArray, String[] strColumnNames)
// NB: All strArray cells will be editable and first column is locked.
JSpreadSheet(this, JScrollPane scrollPane, String[][] strEntireSpreadSheet,
boolean bLockFirstColumn, boolean[][] bCellEditable)
JSpreadSheet(this, JScrollPane scrollPane, String[][] strEntireSpreadSheet,
boolean bLockFirstColumn)
// NB: All strArray cells will be editable.
JSpreadSheet(this, JScrollPane scrollPane, String[][] strEntireSpreadSheet)
// NB: All strArray cells will be editable and first column is locked.
// Interface routine:
public boolean isCellChangeValid(int iRow, int iColumn, String str) {
// When appropriate, use [Link]() to check for valid entry.
..
.
}
// Auxillary routines:
[Link](); // Called to flush out last spread sheet entry
[Link](); // Used by isCellChangeValid to check for valid entry
[Link]();
[Link]();
18
(FW) FixedPointsIntegerDialog
class MyParentFrame implements FixedPointsIntegerInterface
double[] dPointFrom, double[] dPointTo;
FixedPointsIntegerDialog fpd = new FixedPointsIntegerDialog(
this, double[] dPointFrom, double[] dPointTo);
//[Link](b); // The default is false
// Start and Stop
[Link](true);
[Link]();
// Interface routines:
public void getMappedPoint() {
..
.
}
public String getSummaryText() {
return null; for the default summary
..
.
19
(FW) SimulationThread
class MyParent
Create the following:
• Start/Continue button
• Stop button
• Pause checkbox
• Repetitions label
// To set initial text, visibility, and enabling of buttons, checkbox, and label
// call this in the addNotify() method:
SimulationThread(Jbutton jButtonStartContinue, Jbutton jButtonStop,
JcheckBox jCheckBoxPause, Jlabel jLabelRepetitions);
// Start button clicked
if{thread == null) {
ParentThread thread = ParentThread(Jbutton jButtonStartContinue,
Jbutton jButtonStop, JcheckBox jCheckBoxPause,
Jlabel jLabelRepetitions, …);
}
[Link]();
// Stop button clicked
[Link]();
thread = null;
class MyParentThread extends SimulationThread implements SimulationThreadInterface
public ParentThread(Jbutton jButtonStartContinue, Jbutton jButtonStop,
JcheckBox jCheckBoxPause, Jlabel jLabelRepetitions, …) {
super(Jbutton jButtonStartContinue, Jbutton jButtonStop,
JcheckBox jCheckBoxPause, Jlabel jLabelRepetitions, int iRepsPerPrint);
super(Jbutton jButtonStartContinue, Jbutton jButtonStop,
JcheckBox jCheckBoxPause, Jlabel jLabelRepetitions);
[Link](this);
..
.
}
// Auxillary routines:
[Link]();
[Link]();
// Interface routines:
public void runOneRepetition() {
..
.
}
public void reportResults() {
..
.
}
20
(FW) FileManagement
class MyParentFrame implements JFileManagementInterface
Create the following:
• File JMenuBar, JMenu, JMenuItem
• The following menu items: New, Open, Save, SaveAs, and Close
MyFileClass myFileClass = new MyFileClass(strFileExtension, jMenuItemSave,
jMenuItemSaveAs, jMenuItemClose)
// Menubar action routines
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
class MyFileClass extends JFileManagement implements JFileManagementInterface() {
MyFileClass(String strFileExtension, JMenuItem jMenuItemSave,
JMenuItem jMenuItemSaveAs, JMenuItem jMenuItemClose)
// NB: One of the following two constructors is necessary
super(strFileExtension, jMenuItemSaveAs, jMenuItemSave, jMenuItemClose);
super(); // I don’t understand this one, unless the other items are unwanted.
// NB: The following call is necessary to set the interface class
[Link](this);
NB: Typically, you want to pass the data entry class (e.g., the class that contains the
spread sheet to that this class can have access to the data.
// JFileManagement auxillary routines:
[Link]();
[Link]();
[Link](); // Informs JFileManagement that changes have occurred
// Interface routines:
public void initializeFile() { // Sets up and initializes the data classes
..
.
}
public void readFile() {
..
.
}
public void writeFile() {
..
.
}
public void clearFile() { // Don’t know what this does
..
.
}
// NB: bChanges must be set to true if any data are changed.
public boolean isChanged() { // Don’t know how this works
return bChanges;
}
21
JEconLabUtility
(FW) [Link]
class JEconLabUtility econLabUtility = new JEconLabUtility();
[Link] slider = [Link] JEconLabSlider(scrollbar [, label, strPrefix])
init(strSpecs)
init(strSpecs, strPrefix) // strSpecs = “minimum maximum iteration default”
setSliderMinimum(strMinimum)
setSliderMinimum(strMaximum)
setSliderMinimum(strIncrement)
setSliderMinimum(strDefault)
setSliderPrefix(strPrefix)
setSliderDecimals(iDecimals)
setSliderVisible(bIsVisible)
setSliderValue(dValue)
getSliderInteger()
getSliderDouble()
getSliderString()
getSliderMinimum()
getSliderMaximum()
getSliderIncrement()
getSliderDefault()
isSliderValueEqual(dValue)
isSliderVisible()
updateSliderValue()
(FW) [Link]
class JEconLabUtility econLabUtility = new JEconLabUtility();
[Link] search = [Link] JEconLabSearch(sliderSearch
[, labelSearch, strSearchMessages])
init(strSearchMessages)
isSliderValueOptimal(dOptimalValue)
(FW) [Link]
class JEconLabUtility econLabUtility = new JEconLabUtility();
[Link] search = [Link] JEconLabSearch(sliderSearch
[, labelSearch, strSearchMessages])
init(strSearchMessages)
isSliderValueOptimal(dOptimalValue)
(FW) [Link]
class JEconLabUtility econLabUtility = new JEconLabUtility();
[Link] econLabButtonGroup =
[Link] JEconLabButtonGroup (buttonGroup);
updateButtonGroup(buttonSelected);
22
(FW) [Link] – Static routines
[Link](frame, rectangle);
(FW) [Link] – Static routines
double[] [Link](dInitial, dNew);
double[] [Link](
dElasticity, dQuantity, dPrice);
double[] [Link]. ConvertElasticityToCurveInteceptAndSlope(
dElasticity, dQuantity, dPrice);
(FW) [Link] – Static routines
double[] [Link](
dDemandFunctionConstant, dDemandFunctionOwnPriceCoef
[, dDemandFunctionCrossPriceCoef] );
double[] [Link](
dDemandCurveIntercept, dDemandCurveSlope)
double[] calDemandFunctionConstantAndCoef(double dDemandCurveIntercept,
double dDemandCurveSlope)
(FW) [Link] – Static routines
See [Link]
(FW) [Link] – Static variables
Eclipse-Window Builder Help
November 11, 2018
Creating a project:
• Toolbar Menu: New icon’s drop down list (not the icon itself) – Java Project
• Specify the name of the project.
• Finish
Creating a frame, or applet, or …
• Highlight project.
• Toolbar Menu: New icon itself ( not the icon’s drop down list) – WindowBuilder – Swing
Designer – JFrame (for application) or JApplet
• Name frame or applet
• Specify package (if necessary) and name
• Finish
• Modify [Link](…) to [Link](null)
• Delete import [Link];
• Right click warning icon – Quick Fix – Add default serial ID
Creating a panel
• Apparently the WindowBuilder Designer does not work properly until one component has been
attached to the contentPane “by hand.” So, use the [Link] in the subdirectory
eclipse\Templates which includes btnDummy which can be deleted later.
Displaying panels
• Window (menu item) - Show View (drop down box)
Accessing WindowBuilder
• Right click Java file
• Open Java file - Open With – WindowBuilder Editor
Create a library Jar file and the Jar description file
• File (menu item): Select Export
• Export window: Select Java – JAR file
• JAR File Specification window
o Select the resources to export window: Select files to include in the library
o Select the export destination: Specify Jar file name. (I’m using the root directory of
FWLibraries for the location of the library files; also, check the export name.)
o Next
• JAR Packaging Options
o Be certain the Save the description of this JAR file in the workspace is selected
o Name Description file
• Finish
Create a library Jar file from a Jar description file
• Right double click Jar description file (*.jardesc)
• Finish
Add Libraries to Project
• Right click on project – Build Path – Configure Build Path…
• Properties for project: Click Add Jars
• Jar Selection window: Find and then click on the wanted library jar
The library will now be listed as part of the project.
2
Create a Runnable Jar Application File and an Ant file: Produces a jar file that can be run as an
application or applet and an ANT file which can be used in the future to create the jar file.
• Highlight the “root” file for the application.
• File (menu item): Select Export
• Export window: Select Runnable JAR file
• Runnable JAR File Export window: NB: Be careful to specify the correct Launch
configuration, Export destination, and ANT script location. Eclipse saves the last ones so if
you are creating a new jar file you must change all three.
o Launch configuration: Select
o Export destination: Click Browse
o Library handling: Select “Extract required …”
o Save as ANT script: Check
o ANT script location: Click Browse
• Finish
Create a Runnable Jar Application File from an Ant file: Produces a jar file that can be run as an
application or applet
• In Eclipse, Right click the ANT file which has an xml extension.
• Click Run As
• Click 1 Ant Build
Creating Jar Files for Applets
• In the (package) source directory create a Java application that accesses the main class.
• Create a jar file for the application using the application’s launch configuration. (Note that the
applet does not have a launch configuration.
• The jar file can be run as an applet or application.
Adding a Project to a Working Sets
• Click the “triangle” in the top line of the Project Explorer
• Check the working set to contain the project
• Click Edit Active Working Set
• Select the project and click Add
Jar Creation Xml Ant files do not appear in Eclipse’s Project Explorer
• In Window’s Explorer, cut the files and paste to somewhere else.
• Cut the files from where they were pasted.
• In Eclipse, paste them to the appropriate project.
Jar Creation Xml Ant Script Problem
• Right click on your ant script
• Select Run as
• Select External tool configurations...
• Select JRE tab
• Select Run in the same JRE as the workspace
3
Launch Configurations
• To determine which launch configuration an application is using:
o Run the application.
o Click Run in the Eclipse menu and then click Run Launch Configuration.
o The launch configuration used will be lightly highlighted.
• To determine if a launch configuration is being used by some application
o Click Run in the Eclipse menu and then click Run Launch Configuration.
o Double click on the launch configuration in question.
o If the launch configuration is being used, the application will run; otherwise and
error ensues.