datawindow java
2024-07-21 02:06:00
供稿:网友
/*///////////////////////////////////////////////////////////////////////// * * this is a basic java datawindow example. * i want explaine you how to use a datawindow control for java development. * (its so basic...) * *autor: * david arcia 09-09-2002 ([email protected]) *//////////////////////////////////////////////////////////////////////////*/import javax.swing.joptionpane;import javax.swing.jframe;import powersoft.datawindow.jdatawindowcontrol;import powersoft.datawindow.blob;import powersoft.powerj.db.java_sql.transaction;public class jdatawindow extends jframe{//the datawindowprivate jdatawindowcontrol dwcactual;//the powerbuilder library path (where dataobjects are stored)private final string libreria = new string("c:/pb7/java.pbl");//transaction objetc for database connectionprivate transaction trans; //contructor public jdatawindow() { //new datawindow controldwcactual = getdatawindow("dw_products",true,true,true);//not null ?if(dwcactual == null) return; }//ends method/******************************************************************************** * connection using powersoft transaction object (as sqlca in powerbuilder) ********************************************************************************/ //this method connect with database (by example, a oracle database) public boolean setconnect(){ trans = new transaction(); trans.registerdriver( "oracle.jdbc.driver.oracledriver" ); trans.setdatasource("jdbc:oracle:thin:@192.168.22.10:1521:falcon"); trans.setuserid( "rjimenez" ); trans.setpassword( "defalcon" ); //error ? if(!trans.connect()){ system.err.println("connection failed."); return false; } return true; }//ends method /******************************************************************************** * java datawindow's creation ********************************************************************************/ //create a datawindow public jdatawindowcontrol getdatawindow(string dataobject){ jdatawindowcontrol dwc = new jdatawindowcontrol(); //assign a datawindow library dwc.setsourcefilename(libreria); //assign a datawindow object to the dw control dwc.setdatawindowobjectname(dataobject); //some properties... dwc.setvscroll( true ); dwc.insertrow(0); //assign the transaction object to dw dwc.settransaction(trans); //return object created return dwc; }//ends method //optional...method for row selection public void selectrow(int row){ if(row > 0){dwcactual.selectrow(0,false);dwcactual.selectrow(row,true);dwcactual.scrolltorow(row);dwcactual.setrow(row);} }//ends method //optional... for to make a datawindow editable or not public void seteditable(jdatawindowcontrol dwc, boolean editar){ //accept text dwcactual.accepttext(); //get column number int cols = integer.parseint(dwc.describe("datawindow.column.count")); ////////////////////////////////////////////////////////////////////////// string indicador = (editar) ? "1" : "0";////////////////////////////////////////////////////////////////////////// editable = indicador == "1"; //change the editable porperty for(int cont=1; cont <= cols; cont++){ dwc.modify("#" + cont + ".tabsequence = " + indicador); } }//ends method //optional... insert new row to datawindows end. public void getnewrow(){ int row=dwcactual.insertrow(0); selectrow(row); }//final de metodo //optional... delete a datawindow row public void deleterow(){int boton=joptionpane.showconfirmdialog(null,"delete actual row ?", "deleting", joptionpane.yes_no_option);if(boton == 0) dwcactual.deleterow(dwcactual.getrow()); }//fin de metodo /********************************************************************************* this are the datawindow's event managers** the events that support datawindow are clasificated in differents interfaces* according it function.*********************************************************************************interfaces:mouselistener,focuslistener,databaselistener,editchangedlistener,itemlistener,printlistener,rowchangelistener, etc...datawindow events:public void leftbuttondoubleclick (mouseevent event){}public void leftbuttonclick (mouseevent event){}public void leftbuttondown ( mouseevent event){}public void leftbuttonup ( mouseevent event){}public void middlebuttonclick ( mouseevent event){}public void middlebuttondoubleclick ( mouseevent event){}public void mousemove ( mouseevent event){}public void rightbuttonclick ( mouseevent event){}public void rightbuttondoubleclick ( mouseevent event){}public void rightbuttondown ( mouseevent event){}public void rightbuttonup ( mouseevent event){}public void getfocus ( focusevent event){}public void losefocus ( focusevent event){}public void dberror ( databaseevent event){}public void sqlpreview ( databaseevent event){}public void editchanged ( editchangedevent event){}public void itemchanged ( itemevent event){}public void itemchangeaccepted ( itemevent event){}public void itemerror ( itemevent event){}public void itemfocuschanged ( itemevent event){} public void printending ( printevent event){}public void printmarginchanging ( printevent event){}public void printpagestarting ( printevent event){} public void printstarting ( printevent event){}public void retrieveend ( retrieveevent event){}public void retrieverow ( retrieveevent event){}public void retrievestart ( retrieveevent event){} public void rowchanged ( rowchangeevent event){}public void rowchanging ( rowchangeevent event){}etc...********************************************************************************/}//ends classe