//Book.java
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.data.*;
import com.ms.wfc.data.ui.*;
import com.ms.wfc.io.*;
public class Book extends Form
{
// Variables
String CurrentDirectory = new String();
String vrecordset = new String();
Image imag;
File fil ;
// Navigation, Connection and Recordset
Connection m_con;
Recordset m_rs;
// Search By Word, Connection and Recordset
Connection m_con_word;
Recordset m_rs_word;
// Search By Address, Connection and Recordset
Connection m_con_search;
Recordset m_rs_address;
DataBinder m_dataBinder;
protected void finalize()
{
try
{
m_rs.close();
m_con.close();
}
catch (Exception e)
{
handleADOException( e );
}
}
public void dispose()
{
super.dispose();
components.dispose();
}
public Book()
{
// Required for Visual J++ Form Designer support
initForm();
this.show();
this.update();
// Disable
contols
Set_Tab_Panel(false);
// Current dirctory
CurrentDirectory = fil.getCurrentDirectory();
//TODO: Add any constructor code after initForm call
try
{
openDataConnection();
initializeBindings();
//Procedures,
Search operation
openConnection_search();
openRecordset_search_word();
// enable
Set_Tab_Panel(true);
// Initial
m_rs.moveFirst();
m_rs.move(2);
CalculValue();
SetButtons(true);
pictureBox1.setImage(imag.loadImage(fil.open(String.valueOf(CurrentDirectory.toString()
+ "\\Pic\\forum.gif"))));
pictureBox2.setImage(imag.loadImage(fil.open(String.valueOf(CurrentDirectory.toString()
+ "\\Pic\\Christus-th.gif"))));
}
catch (Exception e)
{
handleADOException( e );
}
}
public void formClose(Event e)
{
Application.exit();
this.close();
}
public void btnClose_Click(Object sender, Event evt)
{
Application.exit();
this.close();
}
void openDataConnection()
{
m_con = new Connection();
m_rs = new Recordset();
m_con.setConnectionString ("PROVIDER=Microsoft.Jet.OLEDB.3.51;Data
Source=C:\\TestVJ\\Pic\\KJV.mdb");
m_con.setConnectionString ("PROVIDER=Microsoft.Jet.OLEDB.3.51;Data
Source=" + CurrentDirectory.toString() + "\\Pic\\KJV.mdb");
m_con.setCursorLocation (AdoEnums.CursorLocation.CLIENT);
m_con.open();
m_rs.setActiveConnection(m_con);
m_rs.setSource("select Book, BookTitle, Chapter,
Verse, TextData from BibleTable");
m_rs.setCursorType(AdoEnums.CursorType.STATIC);
m_rs.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
m_rs.setLockType(AdoEnums.LockType.OPTIMISTIC);
m_rs.open();
dataNavigator.setDataSource(m_rs);
}
void initializeBindings()
{
try
{
m_dataBinder = new DataBinder(m_rs);
m_dataBinder.setBindings(new DataBinding[] {
new DataBinding( editBook,"Text","Book"),
new DataBinding( editBookTitle,"Text","BookTitle"),
new DataBinding( editChapter,"Text","Chapter"),
new DataBinding( editVerse,"Text","Verse"),
new DataBinding( editTextData,"Text","TextData")
});
}
catch (Exception e)
{
handleADOException( e );
}
}
// Procedure -
Search operation, connection
void openConnection_search()
{
m_con_search = new Connection();
m_con_search.setConnectionString
("PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" +
CurrentDirectory.toString() + "\\Pic\\KJV.mdb");
m_con_search.setCursorLocation (AdoEnums.CursorLocation.CLIENT);
m_con_search.open();
}
// Procedure - Search operation by word, recordset
void openRecordset_search_word()
{
m_con_word = new Connection();
m_con_word.setConnectionString ("PROVIDER=Microsoft.Jet.OLEDB.3.51;Data
Source=" + CurrentDirectory.toString() + "\\Pic\\KJV.mdb");
m_con_word.setCursorLocation (AdoEnums.CursorLocation.CLIENT);
m_con_word.open();
m_rs_word = new Recordset();
m_rs_word.setActiveConnection(m_con_word);
m_rs_word.setSource("select BookTitle, Book, Chapter, Verse, TextData
from BibleTable");
m_rs_word.setCursorType(AdoEnums.CursorType.STATIC);
m_rs_word.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
m_rs_word.setLockType(AdoEnums.LockType.OPTIMISTIC);
m_rs_word.open();
}
// Procedure - Search operation by address, recordset
void openRecordset_search_address(String recordset_command)
{
m_rs_address = new Recordset();
m_rs_address.setActiveConnection(m_con_search);
m_rs_address.setSource(recordset_command.toString());
m_rs_address.setCursorType(AdoEnums.CursorType.STATIC);
m_rs_address.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
m_rs_address.setLockType(AdoEnums.LockType.OPTIMISTIC);
m_rs_address.open();
}
void handleADOException(Exception e)
{
e.printStackTrace();
MessageBox.show( e.toString(), "Book" );
}
// >>>>>>>>>>>>
Navigation Controls >>>>>>>>>>>>
// Navigation control
public void btnFirst_click(Object source, Event e)
{
m_rs.moveFirst();
m_rs.move(2);
CalculValue();
SetButtons(true);
}
// Navigation control
public void btnPrevious_click(Object source, Event e)
{
m_rs.movePrevious();
CalculValue();
if (m_rs.getRecordCount() > 0 && editBook.getText().equals("01") &&
editChapter.getText().equals("001") && editVerse.getText().equals("001"))
SetButtons(true);
else
SetButtonsAll(true);
}
// Navigation control
public void btnNext_click(Object source, Event e)
{
m_rs.moveNext();
CalculValue();
if (m_rs.getRecordCount() > 0 && editBook.getText().equals("66") &&
editChapter.getText().equals("001") && editVerse.getText().equals("001"))
SetButtons(false);
else
SetButtonsAll(true);
}
// Navigation control
public void btnLast_click(Object source, Event e)
{
m_rs.moveLast();
CalculValue();
SetButtons(false);
}
// Procedure - Book, BookTitle, Chapter and Verse Values
void CalculValue()
{
editBook.setText(m_rs.getField("Book").getString());
editBookTitle.setText(m_rs.getField("BookTitle").getString());
editChapter.setText(m_rs.getField("Chapter").getString());
editVerse.setText(m_rs.getField("Verse").getString());
editTextData.setText(m_rs.getField("TextData").getString());
lbposition.setText("Rec: " + String.valueOf(m_rs.getAbsolutePosition()).toString());
}
// Procedure - Enable or disable navigation controls
void SetButtons(boolean bVal)
{
btnFirst.setEnabled(!bVal);
btnPrevious.setEnabled(!bVal);
btnNext.setEnabled(bVal);
btnLast.setEnabled(bVal);
}
// Enable or disable navigation controls
void SetButtonsAll(boolean bVal)
{
btnFirst.setEnabled(bVal);
btnPrevious.setEnabled(bVal);
btnNext.setEnabled(bVal);
btnLast.setEnabled(bVal);
}
// Enable or disable these controls
void Set_Tab_Panel(boolean bVal)
{
panel1.setEnabled(bVal);
panel2.setEnabled(bVal);
tabControl1.setEnabled(bVal);
}
// <<<<<<<<<<<<
Navigation Controls <<<<<<<
Search Operation, By Word
Search Operation, By Address
/**>>>>>>>>>>>>>>>
Controls >>>>>>>>>>>>>>>>>>>>>>
* NOTE: The following code is required by the Visual J++
form
* designer. It can be modified using the form editor. Do
not
* modify it using the code editor.
*/
Container components = new Container();
Label labelBook = new Label();
Edit editBook = new Edit();
Label labelBookTitle = new Label();
Edit editBookTitle = new Edit();
Label labelChapter = new Label();
Edit editChapter = new Edit();
Label labelVerse = new Label();
Edit editVerse = new Edit();
Label labelTextData = new Label();
Edit editTextData = new Edit();
Button btnClose = new Button();
Panel panel1 = new Panel(components);
DataNavigator dataNavigator = new DataNavigator();
PictureBox pictureBox1 = new PictureBox();
PictureBox
pictureBox2 = new PictureBox();
Label label12 =
new Label();
Label label13 =
new Label();
GroupBox
groupBox1 = new GroupBox();
TabControl
tabControl1 = new TabControl();
TabPage tabPage1 = new TabPage();
GroupBox groupBox3 = new GroupBox();
TabPage tabPage2 = new TabPage();
GroupBox groupBox4 = new GroupBox();
Panel panel2 = new Panel(components);
Label lbposition = new Label();
Button btnFirst = new Button();
Button btnPrevious = new Button();
Button btnNext = new Button();
Button btnLast = new Button();
ComboBox
comboTitle = new ComboBox();
ComboBox comboBook = new ComboBox();
ComboBox comboChapter = new ComboBox();
ComboBox comboVerse = new ComboBox();
Label label11 = new Label();
Label label10 = new Label();
Label label9 = new Label();
Label label8 = new Label();
Label lbInfo1 = new Label();
Label lbInfo =
new Label();
ListView listViewSearch = new ListView();
Edit editWord = new Edit();
Label label5 = new Label();
Button btnDisplay = new Button();
RichEdit richEdit1 = new RichEdit();
private void initForm()
{
this.setBackColor(Color.CONTROL);
this.setLocation(new Point(7, 7));
this.setTabIndex(-1);
this.setTabStop(true);
this.setText("Book");
this.setAutoScaleBaseSize(13);
this.setAutoScroll(true);
this.setStartPosition(FormStartPosition.CENTER_SCREEN);
this.setSize(new Point(420, 240));
this.setClientSize(new Point(420, 240));
labelBook.setBackColor (Color.CONTROL);
labelBook.setTabIndex ( 0 );
labelBook.setText ("Book" );
labelBook.setLocation (new Point ( 10, 20 ) );
labelBook.setSize (new Point ( 100, 20 ) );
labelBook.setLocation(new Point(8, 280));
labelBook.setSize(new Point(48, 15));
editBook.setBackColor (Color.WINDOW);
editBook.setTabIndex ( 1 );
editBook.setText ("Book" );
editBook.setLocation (new Point ( 120, 20 ) );
editBook.setCursor (Cursor.IBEAM);
editBook.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editBook.setSize (new Point ( 280, 20 ) );
editBook.setMultiline(true);
editBook.setBackColor(Color.CONTROL);
editBook.setLocation(new Point(56, 272));
editBook.setSize(new Point(72, 20));
editBook.setText("");
editBook.setReadOnly(true);
labelBookTitle.setBackColor (Color.CONTROL);
labelBookTitle.setTabIndex ( 2 );
labelBookTitle.setText ("BookTitle" );
labelBookTitle.setLocation (new Point ( 10, 50 ) );
labelBookTitle.setSize (new Point ( 100, 20 ) );
labelBookTitle.setLocation(new Point(136, 280));
labelBookTitle.setSize(new Point(48, 15));
editBookTitle.setBackColor (Color.WINDOW);
editBookTitle.setTabIndex ( 3 );
editBookTitle.setText ("BookTitle" );
editBookTitle.setLocation (new Point ( 120, 50 ) );
editBookTitle.setCursor (Cursor.IBEAM);
editBookTitle.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editBookTitle.setSize (new Point ( 280, 20 ) );
editBookTitle.setMultiline(true);
editBookTitle.setBackColor(Color.CONTROL);
editBookTitle.setLocation(new Point(184, 272));
editBookTitle.setSize(new Point(136, 20));
editBookTitle.setText("");
editBookTitle.setReadOnly(true);
labelChapter.setBackColor (Color.CONTROL);
labelChapter.setTabIndex ( 4 );
labelChapter.setText ("Chapter" );
labelChapter.setLocation (new Point ( 10, 80 ) );
labelChapter.setSize (new Point ( 100, 20 ) );
labelChapter.setLocation(new Point(8, 304));
labelChapter.setSize(new Point(48, 15));
editChapter.setBackColor (Color.WINDOW);
editChapter.setTabIndex ( 5 );
editChapter.setText ("Chapter" );
editChapter.setLocation (new Point ( 120, 80 ) );
editChapter.setCursor (Cursor.IBEAM);
editChapter.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editChapter.setSize (new Point ( 280, 20 ) );
editChapter.setMultiline(true);
editChapter.setBackColor(Color.CONTROL);
editChapter.setLocation(new Point(56, 296));
editChapter.setSize(new Point(72, 20));
editChapter.setText("");
editChapter.setReadOnly(true);
labelVerse.setBackColor (Color.CONTROL);
labelVerse.setTabIndex ( 6 );
labelVerse.setText ("Verse" );
labelVerse.setLocation (new Point ( 10, 110 ) );
labelVerse.setSize (new Point ( 100, 20 ) );
labelVerse.setLocation(new Point(136, 304));
labelVerse.setSize(new Point(48, 15));
editVerse.setBackColor (Color.WINDOW);
editVerse.setTabIndex ( 7 );
editVerse.setText ("Verse" );
editVerse.setLocation (new Point ( 120, 110 ) );
editVerse.setCursor (Cursor.IBEAM);
editVerse.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editVerse.setSize (new Point ( 280, 20 ) );
editVerse.setMultiline(true);
editVerse.setBackColor(Color.CONTROL);
editVerse.setLocation(new Point(184, 296));
editVerse.setSize(new Point(136, 20));
editVerse.setText("");
editVerse.setReadOnly(true);
labelTextData.setBackColor (Color.CONTROL);
labelTextData.setTabIndex ( 8 );
labelTextData.setText ("TextData" );
labelTextData.setLocation (new Point ( 10, 140 ) );
labelTextData.setSize (new Point ( 100, 20 ) );
editTextData.setBackColor (Color.WINDOW);
editTextData.setTabIndex ( 9 );
editTextData.setText ("TextData" );
editTextData.setLocation (new Point ( 120, 140 ) );
editTextData.setCursor (Cursor.IBEAM);
editTextData.setAnchor(ControlAnchor.TOPLEFTRIGHT);
editTextData.setSize (new Point ( 280, 20 ) );
editTextData.setMultiline(true);
editTextData.setScrollBars(ScrollBars.VERTICAL);
editTextData.setBackColor(Color.CONTROL);
editTextData.setLocation(new Point(8, 336));
editTextData.setSize(new Point(312, 96));
editTextData.setText("");
editTextData.setReadOnly(true);
panel1.setDock(ControlDock.BOTTOM);
panel1.setLocation(new Point(0, 170));
panel1.setSize(new Point(420, 50));
panel1.setTabIndex(10);
panel1.setLocation(new Point(248, 448));
panel1.setSize(new Point(72, 32));
btnClose.setLocation(new Point(175, 8));
btnClose.setSize(new Point(70, 30));
btnClose.setTabIndex(11);
btnClose.setTabStop(true);
btnClose.setText("&Close");
btnClose.addOnClick(new EventHandler(this.btnClose_Click));
dataNavigator.setDock(ControlDock.BOTTOM);
dataNavigator.setLocation(new Point(10, 210));
dataNavigator.setSize(new Point(400, 20));
dataNavigator.setTabIndex(12);
dataNavigator.setTabStop(false);
dataNavigator.setText("");
pictureBox1.setLocation(new Point(72, 24));
pictureBox1.setSize(new Point(184, 200));
pictureBox1.setTabIndex(0);
pictureBox1.setTabStop(false);
pictureBox1.setText("pictureBox1");
label12.setFont(new Font("Times New Roman", 10.0f, FontSize.POINTS,
FontWeight.BOLD, true, true, false, CharacterSet.DEFAULT, 0));
label12.setLocation(new Point(8, 240));
label12.setSize(new Point(136, 16));
label12.setTabIndex(11);
label12.setTabStop(false);
label12.setText("Record data boxes ...");
groupBox1.setBackColor(Color.CONTROLDARK);
groupBox1.setLocation(new Point(328, -8));
groupBox1.setSize(new Point(16, 496));
groupBox1.setTabIndex(12);
groupBox1.setTabStop(false);
groupBox1.setText("groupBox1");
pictureBox2.setLocation(new Point(416, 24));
pictureBox2.setSize(new Point(224, 200));
pictureBox2.setTabIndex(1);
pictureBox2.setTabStop(false);
pictureBox2.setText("pictureBox2");
label13.setFont(new Font("Times New Roman", 10.0f, FontSize.POINTS,
FontWeight.BOLD, true, true, false, CharacterSet.DEFAULT, 0));
label13.setLocation(new Point(360, 248));
label13.setSize(new Point(100, 16));
label13.setTabIndex(2);
label13.setTabStop(false);
label13.setText("Search ...");
abControl1.setLocation(new Point(352, 272));
tabControl1.setSize(new Point(320, 208));
tabControl1.setTabIndex(0);
tabControl1.setText("tabControl1");
tabControl1.setItemSize(new Point(100, 21));
tabControl1.setMultiline(true);
tabControl1.setSelectedIndex(0);
tabPage1.setLocation(new Point(4, 25));
tabPage1.setSize(new Point(312, 179));
tabPage1.setTabIndex(0);
tabPage1.setText(" By Word ");
tabPage1.setToolTipText(null);
groupBox3.setFont(new Font("Courier New", 10.0f, FontSize.POINTS,
FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
groupBox3.setSize(new Point(312, 180));
groupBox3.setTabIndex(0);
groupBox3.setTabStop(false);
groupBox3.setText("");
tabPage2.setLocation(new Point(4, 25));
tabPage2.setSize(new Point(312, 179));
tabPage2.setTabIndex(1);
tabPage2.setText(" By address ");
tabPage2.setToolTipText(null);
groupBox4.setSize(new Point(312, 176));
groupBox4.setTabIndex(0);
groupBox4.setTabStop(false);
groupBox4.setText("");
panel2.setLocation(new Point(8, 448));
panel2.setSize(new Point(240, 32));
panel2.setTabIndex(6);
panel2.setText("");
lbposition.setLocation(new Point(8, 8));
lbposition.setSize(new Point(56, 16));
lbposition.setTabIndex(4);
lbposition.setTabStop(false);
lbposition.setText("Record");
btnFirst.setLocation(new Point(72, 0));
btnFirst.setSize(new Point(40, 30));
btnFirst.setTabIndex(0);
btnFirst.setText("First");
btnPrevious.setLocation(new Point(112, 0));
btnPrevious.setSize(new Point(40, 30));
btnPrevious.setTabIndex(1);
btnPrevious.setText("Prev.");
btnNext.setLocation(new Point(160, 0));
btnNext.setSize(new Point(40, 30));
btnNext.setTabIndex(2);
btnNext.setText("Next");
btnLast.setLocation(new Point(200, 0));
btnLast.setSize(new Point(40, 30));
btnLast.setTabIndex(3);
btnLast.setText("Last");
comboTitle.setLocation(new Point(112, 32));
comboTitle.setSize(new Point(128, 21));
comboTitle.setTabIndex(1);
comboTitle.setText("");
comboBook.setLocation(new Point(112, 64));
comboBook.setSize(new Point(128, 21));
comboBook.setTabIndex(2);
comboBook.setText("");
comboChapter.setLocation(new Point(112, 96));
comboChapter.setSize(new Point(128, 21));
comboChapter.setTabIndex(3);
comboChapter.setText("");
comboVerse.setLocation(new Point(112, 128));
comboVerse.setSize(new Point(128, 21));
comboVerse.setTabIndex(4);
comboVerse.setText("");
label11.setLocation(new Point(56, 136));
label11.setSize(new Point(48, 15));
label11.setTabIndex(5);
label11.setTabStop(false);
label11.setText("Verse :");
label10.setLocation(new Point(56, 104));
label10.setSize(new Point(48, 15));
label10.setTabIndex(7);
label10.setTabStop(false);
label10.setText("Chapter :");
label9.setLocation(new Point(56, 72));
label9.setSize(new Point(48, 15));
label9.setTabIndex(8);
label9.setTabStop(false);
label9.setText("Book :");
label8.setLocation(new Point(56, 40));
label8.setSize(new Point(48, 15));
label8.setTabIndex(6);
label8.setTabStop(false);
label8.setText("Title :");
lbInfo1.setLocation(new Point(16, 160));
lbInfo1.setSize(new Point(275, 14));
lbInfo1.setTabIndex(0);
lbInfo1.setTabStop(false);
lbInfo1.setText("");
lbInfo.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS,
FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
lbInfo.setLocation(new Point(8, 168));
lbInfo.setSize(new Point(288, 14));
lbInfo.setTabIndex(1);
lbInfo.setTabStop(false);
lbInfo.setText("");
listViewSearch.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS,
FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
listViewSearch.setLocation(new Point(8, 48));
listViewSearch.setSize(new Point(296, 117));
listViewSearch.setTabIndex(0);
listViewSearch.setText("listView1");
listViewSearch.setMultiSelect(false);
listViewSearch.setView(ViewEnum.REPORT);
editWord.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS,
FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
editWord.setLocation(new Point(8, 24));
editWord.setSize(new Point(176, 20));
editWord.setTabIndex(3);
editWord.setText("");
label5.setFont(new Font("Times New Roman", 9.0f, FontSize.POINTS,
FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
label5.setLocation(new Point(8, 8));
label5.setSize(new Point(184, 14));
label5.setTabIndex(4);
label5.setTabStop(false);
label5.setText("Type in the word to search for :");
btnDisplay.setEnabled(false);
btnDisplay.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS,
FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
btnDisplay.setLocation(new Point(200, 24));
btnDisplay.setSize(new Point(88, 23));
btnDisplay.setTabIndex(2);
btnDisplay.setText("Display");
richEdit1.setFont(Font.DEFAULT_GUI);
richEdit1.setForeColor(Color.WINDOWTEXT);
richEdit1.setLocation(new Point(560, 232));
richEdit1.setSize(new Point(100, 30));
richEdit1.setTabIndex(3);
richEdit1.setText("");
richEdit1.setVisible(false);
this.setNewControls(new Control[] {
richEdit1,
panel2,
tabControl1,
label12,
label13,
pictureBox1,
pictureBox2
groupBox1,
dataNavigator,
btnClose,
panel1,
labelBook,
editBook,
labelBookTitle,
editBookTitle,
labelChapter,
editChapter,
labelVerse,
editVerse,
labelTextData,
editTextData
});
panel1.setNewControls(new Control[] {
btnClose
tabControl1.setNewControls(new Control[] {
tabPage1,
tabPage2});
tabPage1.setNewControls(new
Control[] {
groupBox3});
groupBox3.setNewControls(new Control[] {
btnDisplay,
label5,
editWord,
listViewSearch,
lbInfo});
tabPage2.setNewControls(new Control[] {
groupBox4});
groupBox4.setNewControls(new Control[] {
lbInfo1,
label8,
label9,
label10,
label11,
comboVerse,
comboChapter,
comboBook,
comboTitle});
panel2.setNewControls(new Control[] {
btnLast,
btnNext,
btnPrevious,
btnFirst,
lbposition});
});
}
/**
<<<<<<<<<<<<< Controls <<<<<<<<<<<<<<<<<
//NOTE: End of form designer support code.
/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the
application
* via the command line.
*/
public static void main(String args[])
{
Application.run( new Book() );
}
} |