Hi drj,
This is my source program , I have placed hibernate3.jar at $JBOSS_HOME/server/default/lib
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.util.*;
import java.util.zip.*;
import java.io.*;
import java.awt.event.*;
import java.text.*;
import java.sql.*;
import javax.swing.event.*;
//import oracle.jdbc.driver.*;
import java.rmi.*;
import java.net.*;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.*;
import net.sf.jasperreports.view.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class MainApplet extends JApplet
{
SuperPanel superPanel;
public void init()
{
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e){
}
Container c=getContentPane();
superPanel=new SuperPanel(getParameter("VoucherDateDateFormat"));
superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.txtPanel.lblVoucherDate.setText(getParameter("lblVoucherDate"));
superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.txtPanel.txtVoucherDate.setText(superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.ob.getSysDate(getParameter("VoucherDateDateFormat")));
superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.txtPanel.lblNarration.setText(getParameter("lblNarration"));
superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.txtPanel.lblTotalDebit.setText(getParameter("lblTotalDebit"));
superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.txtPanel.lblTotalCredit.setText(getParameter("lblTotalCredit"));
superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.txtPanel.lblFileUpload.setText(getParameter("lblFileUpload"));
superPanel.topPanel.topRightPanel.innerRightPanel.mPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
c.add(superPanel);
superPanel.usernamePasswordPanel.btnLogin.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if(superPanel.usernamePasswordPanel.txtUsername.getText().equals("admin") && superPanel.usernamePasswordPanel.txtPassword.getText().equals("password"))
{
superPanel.cardLayout.show(superPanel,"TopPanel");
}
}
});
superPanel.topPanel.topLeftPanel.treeDemo.tree.addTreeSelectionListener(new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
superPanel.topPanel.topLeftPanel.treeDemo.tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if(nodeInfo.toString().equals("VoucherEntry"))
{
superPanel.topPanel.topRightPanel.innerRightPanel.cardLayout.show(superPanel.topPanel.topRightPanel.innerRightPanel,"VoucherEntryForm");
}
else
{
if(nodeInfo.toString().equals("Menu"))
{
superPanel.topPanel.topRightPanel.innerRightPanel.cardLayout.show(superPanel.topPanel.topRightPanel.innerRightPanel,"BlankPanel");
}
else
{
if(nodeInfo.toString().equals("Logout"))
{
superPanel.cardLayout.show(superPanel,"UsernamePasswordPanel");
}
}
}
}
});
}
}
class SuperPanel extends JPanel
{
UsernamePasswordPanel usernamePasswordPanel;
TopPanel topPanel;
CardLayout cardLayout;
public SuperPanel(String data)
{
cardLayout=new CardLayout();
setLayout(cardLayout);
usernamePasswordPanel=new UsernamePasswordPanel();
topPanel=new TopPanel(data);
add(usernamePasswordPanel,"UsernamePasswordPanel");
add(topPanel,"TopPanel");
}
}
class UsernamePasswordPanel extends JPanel
{
JLabel lblUsername,lblPassword,lblHostString;
JTextField txtUsername,txtPassword,txtHostString;
JButton btnLogin,btnCancel;
JPanel jp1,jp2,jp3,jp4,jp5;
JPanel jp3Left,jp3Meddium,jp3Right;
public UsernamePasswordPanel()
{
setLayout(new GridLayout(3,1));
jp1=new JPanel();
//jp2=new JPanel();
jp3=new JPanel();
jp3.setLayout(new GridLayout(1,3));
jp3Left=new JPanel();
jp3Meddium=new JPanel();
jp3Meddium.setBorder(new BevelBorder(BevelBorder.RAISED));
jp3Meddium.setBackground(Color.darkGray);
jp3Meddium.setLayout(new GridLayout(5,1));
JPanel titlePanel=new JPanel();
titlePanel.setLayout(new GridLayout(2,1));
JPanel labelPanel=new JPanel();
labelPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
labelPanel.setBackground(Color.gray);
JLabel lblTitle=new JLabel("Login");
lblTitle.setForeground(Color.pink);
labelPanel.add(lblTitle);
titlePanel.add(labelPanel);
JPanel userPanel=new JPanel();
lblUsername=new JLabel("Username :");
//lblUsername.setForeground(Color.white);
txtUsername=new JTextField(15);
userPanel.add(lblUsername);
userPanel.add(txtUsername);
JPanel passwordPanel=new JPanel();
lblPassword=new JLabel("Password :");
//lblPassword.setForeground(Color.white);
txtPassword=new JPasswordField(15);
passwordPanel.add(lblPassword);
passwordPanel.add(txtPassword);
JPanel hostStringPanel=new JPanel();
lblHostString=new JLabel("HostString:");
//lblHostString.setForeground(Color.white);
txtHostString=new JTextField(15);
hostStringPanel.add(lblHostString);
hostStringPanel.add(txtHostString);
JPanel buttonPanel=new JPanel();
btnLogin=new JButton("Login");
btnLogin.setMnemonic('L');
buttonPanel.add(btnLogin);
btnCancel=new JButton("Cancel");
btnCancel.setMnemonic('C');
buttonPanel.add(btnCancel);
jp3Meddium.add(titlePanel);
jp3Meddium.add(userPanel);
jp3Meddium.add(passwordPanel);
jp3Meddium.add(hostStringPanel);
jp3Meddium.add(buttonPanel);
jp3Right=new JPanel();
jp3.add(jp3Left);
jp3.add(jp3Meddium);
jp3.add(jp3Right);
//jp4=new JPanel();
jp5=new JPanel();
add(jp1);
// add(jp2);
add(jp3);
// add(jp4);
add(jp5);
}
}
class TopPanel extends JPanel
{
TopLeftPanel topLeftPanel;
TopRightPanel topRightPanel;
JSplitPane jsp;
public TopPanel(String data)
{
topLeftPanel=new TopLeftPanel();
topRightPanel=new TopRightPanel(data);
jsp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,topLeftPanel,topRightPanel);
add(jsp);
}
}
class TopLeftPanel extends JPanel
{
TreeDemo treeDemo;
public TopLeftPanel()
{
treeDemo=new TreeDemo();
add(treeDemo);
}
}
class TopRightPanel extends JPanel
{
JScrollPane scrollPane;
InnerRightPanel innerRightPanel;
public TopRightPanel(String data)
{
innerRightPanel=new InnerRightPanel(data);
scrollPane=new JScrollPane(innerRightPanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
add(scrollPane);
}
}
class InnerRightPanel extends JPanel
{
MainPanel mPanel;
CardLayout cardLayout;
JPanel blankPanel;
public InnerRightPanel(String data)
{
cardLayout=new CardLayout();
setLayout(cardLayout);
mPanel=new MainPanel(data);//getParameter("VoucherDateDateFormat"));
blankPanel=new JPanel();
blankPanel.setBackground(Color.darkGray);
blankPanel.setPreferredSize(new Dimension(780,560));
add(blankPanel,"BlankPanel");
add(mPanel,"VoucherEntryForm");
}
}
class MainPanel extends JPanel implements ActionListener
{
TextPanel txtPanel;
TablePanel tabPanel;
JButton btnSave,btnReject,btnExit;
JTextField txtVoucherNo;
JLabel lblVoucherNo;
JPanel DataPanel,VoucherAndButtonPanel;
JPanel ButtonPanel,VoucherPanel;
Vector lblContent;
DateCalc ob=new DateCalc();
String dateFormat;
SessionFactory sessionFactory;
public MainPanel(String df)
{
dateFormat=df;
setLayout(new BorderLayout());
DataPanel=new JPanel();
DataPanel.setLayout(new GridLayout(2,1));
txtPanel=new TextPanel();
txtPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
tabPanel=new TablePanel();
tabPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
DataPanel.add(txtPanel);
DataPanel.add(tabPanel);
VoucherAndButtonPanel=new JPanel();
VoucherAndButtonPanel.setLayout(new GridLayout(2,1));
ButtonPanel=new JPanel();
btnSave=new JButton("Save");
btnSave.setMnemonic('S');
btnSave.addActionListener(this);
btnReject=new JButton("Reject");
btnReject.setMnemonic('R');
btnReject.addActionListener(this);
btnExit=new JButton("Exit");
btnExit.setMnemonic('E');
btnExit.addActionListener(this);
ButtonPanel.add(btnSave);
ButtonPanel.add(btnReject);
ButtonPanel.add(btnExit);
VoucherPanel=new JPanel();
VoucherPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
lblVoucherNo=new JLabel("Voucher No : ");
txtVoucherNo=new JTextField(8);
txtVoucherNo.setText(DateCalc.genVoucherNo());
//txtVoucherNo.setEditable(false);
txtVoucherNo.setFont(new Font(txtVoucherNo.getFont().getName(),Font.BOLD,txtVoucherNo.getFont().getSize()));
VoucherPanel.add(lblVoucherNo);
VoucherPanel.add(txtVoucherNo);
VoucherAndButtonPanel.add(VoucherPanel);
VoucherAndButtonPanel.add(ButtonPanel);
DataPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
VoucherAndButtonPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
add(DataPanel,BorderLayout.CENTER);
add(VoucherAndButtonPanel,BorderLayout.SOUTH);
/*txtPanel.cbYes.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent ie)
{
if(txtPanel.cbYes.getState()==true)
{
JOptionPane.showMessageDialog(null,"ok");
txtPanel.btnBrowse.setVisible(true);
}
}
});
txtPanel.cbYes.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent ie)
{
if(txtPanel.cbNo.getState()==true)
{
txtPanel.btnBrowse.setVisible(false);
}
}
});*/
tabPanel.table.addMouseListener(new MouseListener()
{
public void mousePressed(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
gridDataCalc();
}
public void mouseEntered(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
});
tabPanel.table.addMouseMotionListener(new MouseMotionListener()
{
public void mouseMoved(MouseEvent me)
{
gridDataCalc();
}
public void mouseDragged(MouseEvent me)
{
}
});
/*tabPanel.comboBox.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent ie)
{
if(comboBox.getSelectedItem().toString().length()>0)
{
for(int i=0;i<DescriptionList.size();i++)
{
String str=(String)DescriptionList.elementAt(i);
if(comboBox.getSelectedItem().toString().equals(str.substring(0,comboBox.getSelectedItem().toString().length())))
{
table.setValueAt(str.substring(comboBox.getSelectedItem().toString().length()),table.getEditingRow(),table.getEditingColumn()+1);
}
}
}
else
{
table.setValueAt("Not Match",table.getEditingRow(),table.getEditingColumn()+1);
}
JOptionPane.showMessageDialog(null,tabPanel.comboBox.getSelectedItem().toString());
}
});*/
tabPanel.table.addKeyListener(new KeyListener()
{
public void keyPressed(KeyEvent ke)
{
}
public void keyReleased(KeyEvent ke)
{
}
public void keyTyped(KeyEvent ke)
{
char ch=ke.getKeyChar();
if(Byte.toString((byte)ch).equals("9"))
{
gridDataCalc();
}//end of if
}//End of keyTyped
});
}
public void gridDataCalc()
{
txtPanel.txtTotalDebit.setText("0.00");
txtPanel.txtTotalCredit.setText("0.00");
try
{
int row;
int col;
TableModel myTableModel=tabPanel.table.getModel();
for(row=0;row<myTableModel.getRowCount();row++)
{
for(col=2;col<myTableModel.getColumnCount();col++)
{
if(tabPanel.table.getValueAt(row,0)!=null)
{
String str=(String)tabPanel.table.getValueAt(row,0);
if(str.length()>0)
{
for(int i=0;i<tabPanel.DescriptionList.size();i++)
{
String str1=(String)tabPanel.DescriptionList.elementAt(i);
if(tabPanel.table.getValueAt(row,0).toString().equals(str1.substring(0,tabPanel.table.getValueAt(row,0).toString().length())))
{
tabPanel.table.setValueAt(str1.substring(tabPanel.table.getValueAt(row,0).toString().length()),row,1);
break;
}
}//end of for
if(col>=2)
{
if(col==2)
{
if(tabPanel.table.getValueAt(row,2)==null || "".equals((String)tabPanel.table.getValueAt(row,2)))
{
tabPanel.table.setValueAt("0.00",row,col);
}
if(Double.parseDouble((String)tabPanel.table.getValueAt(row,2)) >0)
{
tabPanel.table.setValueAt("0.00",row,3);
}
txtPanel.txtTotalDebit.setText(Double.toString(Double.parseDouble(txtPanel.txtTotalDebit.getText())+Double.parseDouble((String)tabPanel.table.getValueAt(row,2))));
}
if(col==3)
{
if(tabPanel.table.getValueAt(row,3)==null || "".equals((String)tabPanel.table.getValueAt(row,3)))
{
tabPanel.table.setValueAt("0.00",row,col);
}
if(Double.parseDouble((String)tabPanel.table.getValueAt(row,3)) >0)
{
tabPanel.table.setValueAt("0.00",row,2);
}
txtPanel.txtTotalCredit.setText(Double.toString(Double.parseDouble(txtPanel.txtTotalCredit.getText())+Double.parseDouble((String)tabPanel.table.getValueAt(row,3))));
}
}
}
}else
{
break;
}
}//End of col
}//End of row
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.toString());
}
}//End of gridDataCalc
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnSave)
{
int row,col;
if(txtPanel.txtVoucherDate.getText().length()>0)
{
try
{
java.util.Date date=new java.util.Date(txtPanel.txtVoucherDate.getText());
try
{
SimpleDateFormat sdf=new SimpleDateFormat("dd-MMM-yyyy");
txtPanel.txtVoucherDate.setText(sdf.format(date));
try
{
//DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
gridDataCalc();
/*Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@192.168.16.7:1521:kris","demo", "demo");
Connection conn=DriverManager.getConnection("jdbc:odbc:ora10g","demo","demo");
Statement stmt = conn.createStatement ();
stmt.executeUpdate("insert into tb_vou_main values('"+txtPanel.txtVoucherDate.getText()+"','"+txtVoucherNo.getText()+"','"+txtPanel.txtNarration.getText()+"',"+txtPanel.txtTotalDebit.getText()+","+txtPanel.txtTotalCredit.getText()+",'"+txtPanel.txtFileUpload.getText()+"')");*/
//DATA SAVED THROUGH HIBERNATE FOR TB_VOU_MAIN
try {
Configuration cfg = new Configuration();
cfg.configure(new File("hibernate.cfg.xml"));
// cfg.addResource("tb_vou_main.hbm.xml");
//cfg.setProperties(System.getProperties());
sessionFactory = cfg.buildSessionFactory();
tb_vou_main mainOb=new tb_vou_main(txtVoucherNo.getText(),new java.util.Date(txtPanel.txtVoucherDate.getText()),txtPanel.txtNarration.getText(),Double.parseDouble(txtPanel.txtTotalDebit.getText()),Double.parseDouble(txtPanel.txtTotalCredit.getText()),txtPanel.txtFileUpload.getText());
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(mainOb);
tx.commit();
session.flush();
session.close();
Configuration cfg1 = new Configuration();
cfg1.configure(new File("hibernate.cfg.xml"));
// cfg1.addResource("tb_vou_det.hbm.xml");
//cfg.setProperties(System.getProperties());
SessionFactory sessionFactory1= cfg1.buildSessionFactory();
TableModel myTableModel=tabPanel.table.getModel();
for(row=0;row<myTableModel.getRowCount();row++)
{
int flag=1;
Vector tabData=new Vector();
for(col=0;col<myTableModel.getColumnCount();col++)
{
if(tabPanel.table.getValueAt(row,col)!=null && "".equals(tabPanel.table.getValueAt(row,col))!=true)
{
tabData.addElement((String)tabPanel.table.getValueAt(row,col));
}
else
{
flag=0;
break;
}
}
if(flag!=0)
{
//stmt.executeUpdate("insert into tb_vou_det values('"+txtVoucherNo.getText()+"','"+tabData.elementAt(0)+"',"+tabData.elementAt(2)+","+tabData.elementAt(3)+")");
Session session1= sessionFactory1.openSession();
Transaction tx1 = session1.beginTransaction();
tb_vou_det detOb=new tb_vou_det(txtVoucherNo.getText(),tabData.elementAt(0).toString(),Double.parseDouble(tabData.elementAt(2).toString()),Double.parseDouble(tabData.elementAt(3).toString()));
session1.save(detOb);
detOb=null;
session1.flush();
tx1.commit();
session.close();
}//END OF IF
}//END OF ROW LOOP
JOptionPane.showMessageDialog(null,"Data Saved successfully");
} catch (Exception e) {
e.printStackTrace();
}
/*stmt.close();
conn.close();*/
ClearData();
//jasperReport code
try
{
JasperDesign jasperDesign = JasperManager.loadXmlDesign("E:/download/Doc/voucher/Voucher.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection con1 = DriverManager.getConnection("jdbc:odbc:ora10g","demo","demo");
Statement s1 = con1.createStatement();
java.util.Map parameters = new java.util.HashMap();
parameters.put("Tittle","Test JasperReport");
JasperPrint report = JasperFillManager.fillReport(jasperReport, parameters, con1);
//JasperExportManager.exportReportToPdfFile(report,"report1.pdf");
JasperViewer.viewReport(report);
}
catch(Exception ex)
{
System.out.print(ex.toString());
}
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.toString());
}
}catch(Exception e)
{
}
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,"This Field ( Voucher Date ) Date Format is not Ok");
txtPanel.txtVoucherDate.setSelectedTextColor(Color.white);
txtPanel.txtVoucherDate.setSelectionColor(Color.red);
txtPanel.txtVoucherDate.select(0,txtPanel.txtVoucherDate.getText().length());
btnExit.transferFocus();
}
}
else
{
JOptionPane.showMessageDialog(null,"This Field ( Voucher Date ) Date Format is not Ok");
txtPanel.txtVoucherDate.setSelectedTextColor(Color.white);
txtPanel.txtVoucherDate.setSelectionColor(Color.red);
txtPanel.txtVoucherDate.select(0,txtPanel.txtVoucherDate.getText().length());
btnExit.transferFocus();
}
}
if(ae.getSource()==btnReject)
{
ClearData();
JOptionPane.showMessageDialog(null,"All Data Cleared");
}//End of Reject Button
}
private void ClearData()
{
try
{
int row,col;
txtPanel.txtVoucherDate.setText(DateCalc.getSysDate(dateFormat));
txtPanel.txtNarration.setText("");
txtPanel.txtTotalDebit.setText("");
txtPanel.txtTotalDebit.setText("0.00");
txtPanel.txtTotalCredit.setText("0.00");
txtPanel.txtFileUpload.setText("");
txtVoucherNo.setText(DateCalc.genVoucherNo());
tabPanel.table.selectAll();
tabPanel.table.clearSelection();
tabPanel.table.transferFocus();
tabPanel.table.setEditingRow(tabPanel.table.getEditingRow()+1);
TableModel myTableModel=tabPanel.table.getModel();
for(row=0;row<myTableModel.getRowCount();row++)
{
for(col=0;col<myTableModel.getColumnCount();col++)
{
tabPanel.table.setValueAt("",row,col);
}
}
btnExit.transferFocus();
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.toString());
}
}
}
class TextPanel extends JPanel implements ActionListener
{
JLabel lblVoucherDate,lblNarration,lblTotalDebit,lblTotalCredit,lblFileUpload;
JTextField txtVoucherDate,txtTotalDebit,txtTotalCredit,txtFileUpload;
JTextField txtNarration;
JButton btnBrowse;
//Checkbox cbYes,cbNo;
//CheckboxGroup cbg;
JPanel jp4;
public TextPanel()
{
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e){
}
setLayout(new GridLayout(4,1));
JPanel jp1=new JPanel();
FlowLayout f1=new FlowLayout(FlowLayout.LEFT);
jp1.setLayout(f1);
lblVoucherDate=new JLabel(" Voucher Date :");
txtVoucherDate=new JTextField(8);
/*cbg=new CheckboxGroup();
cbYes=new Checkbox("Yes",cbg,true);
cbNo=new Checkbox("No",cbg,false);*/
jp1.add(lblVoucherDate);
jp1.add(txtVoucherDate);
//jp1.add(cbYes);
//jp1.add(cbNo);
JPanel jp2=new JPanel();
jp2.setSize(600,40);
FlowLayout f2=new FlowLayout(FlowLayout.LEFT);
jp2.setLayout(f2);
lblNarration=new JLabel(" Narration :");
txtNarration=new JTextField(30);
txtNarration.addCaretListener(new CaretListener()
{
public void caretUpdate(CaretEvent e)
{
if(txtNarration.getText().length()>50)
{
txtNarration.setText(txtNarration.getText().substring(0,50));
}
}
});
//txtNarration.setMaximumSize(30);
jp2.add(lblNarration);
jp2.add(txtNarration);
JPanel jp3=new JPanel();
FlowLayout f3=new FlowLayout(FlowLayout.LEFT);
jp3.setLayout(f3);
lblTotalDebit=new JLabel(" TotalDebit :");
txtTotalDebit=new JTextField(8);
txtTotalDebit.setEditable(false);
txtTotalDebit.setText("0.00");
jp3.add(lblTotalDebit);
jp3.add(txtTotalDebit);
lblTotalCredit=new JLabel(" TotalCredit :");
txtTotalCredit=new JTextField(8);
txtTotalCredit.setEditable(false);
txtTotalCredit.setText("0.00");
jp3.add(lblTotalCredit);
jp3.add(txtTotalCredit);
jp4=new JPanel();
FlowLayout f4=new FlowLayout(FlowLayout.LEFT);
jp4.setLayout(f4);
lblFileUpload=new JLabel(" FileUpload :");
txtFileUpload=new JTextField(30);
jp4.add(lblFileUpload);
jp4.add(txtFileUpload);
btnBrowse=new JButton("Browse");
btnBrowse.setMnemonic('B');
jp4.add(btnBrowse);
btnBrowse.addActionListener(this);
add(jp1);
add(jp2);
add(jp3);
add(jp4);
}
public void actionPerformed(ActionEvent ae)
{
JFileChooser jfc=new JFileChooser();
jfc.showOpenDialog(null);
File f=jfc.getSelectedFile();
txtFileUpload.setText(f.getAbsolutePath());
if(txtFileUpload.getText().length()>0)
{
try
{
FileInputStream fin=new FileInputStream(txtFileUpload.getText());
String str="";
int i;
while((i=fin.read())!=-1)
{
str=str+(char)i;
}
fin.close();
byte b[]=new byte[str.length()];
str.getBytes(0,str.length(),b,0);
ZipOutputStream z=new ZipOutputStream(new FileOutputStream("C:/Documents and Settings/Administrator/Desktop/MyZip.zip"));
ZipEntry ze=new ZipEntry("C:/Documents and Settings/Administrator/Desktop/MyZip.zip");
z.putNextEntry(ze);
z.write(b);
z.close();
ZipInputStream zin=new ZipInputStream(new FileInputStream("C:/Documents and Settings/Administrator/Desktop/MyZip.zip"));
zin.read(b);
fileUploadIntf file=(fileUploadIntf)Naming.lookup("rmi://192.168.16.4"+"/FileServer");
JOptionPane.showMessageDialog(null,file.fileWriteInRemote(b));
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.toString());
}
}
else
{
JOptionPane.showMessageDialog(null,"No Specefied file for Upload");
}//end of if
}
}
class TablePanel extends JPanel{
JPanel jp1,jp2,jp3;
JLabel lblDetail;
JTable table;
TableModel tabModel;
Vector DescriptionList;
JComboBox comboBox;
private String[] columnNames = {"A/c",
"Description",
"Debit",
"Credit"};
private Object[][] data =new Object[30][4];
public TablePanel() {
setLayout(new BorderLayout());
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e){
}
/*Combo add*/
//end code
jp1=new JPanel();
lblDetail=new JLabel("Detail Block");
jp1.add(lblDetail);
jp2=new JPanel();
table = new JTable(data,columnNames);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setPreferredScrollableViewportSize(new Dimension(550, 180));
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
setUpAccountColumn(table.getColumnModel().getColumn(0));
//Add the scroll pane to this panel.
jp2.add(scrollPane);
add(jp1,BorderLayout.NORTH);
add(jp2,BorderLayout.CENTER);
}
//
public void setUpAccountColumn(TableColumn AccountColumn) {
//final JComboBox comboBox;
DescriptionList=new Vector();
//Set up the editor for the Account cells.
comboBox = new JComboBox();
comboBox.setEditable(true);
try
{
//DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@192.168.16.7:1521:kris","demo", "demo");
Connection conn=DriverManager.getConnection("jdbc:odbc:ora10g","demo","demo");
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT Acct_code,Acct_desp FROM tb_acct_mas");
// Print the name out
while (rset.next ())
{
String ac=rset.getString (1);
comboBox.addItem(ac);
DescriptionList.addElement(ac+rset.getString (2));
}
// Close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}catch(Exception e)
{
}
AccountColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
AccountColumn.setCellRenderer(renderer);
} //End of setUpAccountColoumn
}
class DateCalc
{
static String getSysDate(String dateFormat)
{
java.util.Date d=new java.util.Date();
SimpleDateFormat sf=new SimpleDateFormat(dateFormat);
return sf.format(d);
}
static String genVoucherNo()
{
java.util.Date d=new java.util.Date();
SimpleDateFormat sf1=new SimpleDateFormat("dd-MM/");
return sf1.format(d);
}
}
class MyTableModel extends AbstractTableModel {
private String[] columnNames = {"A/c",
"Description",
"Debit",
"Credit"};
private Object[][] data =new Object[30][4];
public final Object[] longValues = {"cacffacsdfs","sbsdushdasdasdsadad","100000","120000"};
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
if (col < 2) {
return false;
} else {
return true;
}
}
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
/*class FileRead
{
public static Vector funRead()
{
Vector v=new Vector();
try
{
String content="";
int i;
FileInputStream fread=new FileInputStream("E:/AppletProperties.txt");
while((i=fread.read())!=-1)
{
content=content+(char)i;
}
StringTokenizer st=new StringTokenizer(content,"=;");
while(st.hasMoreTokens())
{
content=st.nextToken();
v.addElement(st.nextToken());
}
}catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.toString());
}
return v;
}
}*/
class TreeDemo extends JPanel
{
JTree tree;
URL helpURL;
static boolean DEBUG = false;
//Optionally play with line styles. Possible values are
//"Angled" (the default), "Horizontal", and "None".
private static boolean playWithLineStyle = false;
private static String lineStyle = "Horizontal";
//Optionally set the look and feel.
private static boolean useSystemLookAndFeel = false;
public TreeDemo() {
//super(new GridLayout(1,0));
setBackground(Color.darkGray);
//Create the nodes.
DefaultMutableTreeNode top =
new DefaultMutableTreeNode("Menu");
DefaultMutableTreeNode voucherEntryForm =
new DefaultMutableTreeNode("VoucherEntry");
DefaultMutableTreeNode logout =
new DefaultMutableTreeNode("Logout");
top.add(voucherEntryForm);
top.add(logout);
//Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
//Listen for when the selection changes.
// tree.addTreeSelectionListener(this);
if (playWithLineStyle) {
System.out.println("line style = " + lineStyle);
tree.putClientProperty("JTree.lineStyle", lineStyle);
}
//Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
treeView.setPreferredSize(new Dimension(140, 580));
add(treeView);
}//End of constructor
}
Could you please let me know which portion of my code the actual flaw is in. Secondly DO I HAVE TO PUT hibernate3.jar in the .ear file.Why is JBoss Console throws hibernate.properties not found.Can you please suggest me an alternative architecture
Thanks a million for your time.
Deep
_________________ Greetings
|