我已经为报纸商店开发了Java swing应用程序。当我通过从Netbeans运行项目来下单时,该账单将保存为HTML文件到给定目录中,并且devanagari字体会正确呈现。 例如。
但是,当我将自己的swing应用程序部署为EXE安装程序文件并尝试相同的操作时,我发现Devanagari字符已替换为问号。
简而言之,当我尝试通过在Netbeans中运行项目来制作帐单时,所有内容都可以由浏览器正确呈现。与EXE应用程序部署相同的项目后,浏览器无法正确呈现票据字体。
将数据从JTable写入到HTML文件的代码如下。
CallableStatement cstmt;
PreparedStatement pstmt;
static DBConnect db;
Object[][] rowdata;
static String[] columnheads;
static DefaultTableModel dtm;
static ResultSet rs;
static ResultSetMetaData rsmt;
String curName,shop,address,owner,contact,sign,data,destPath;
static int rows,columns,number;
float total, discount;
static TableRowSorter<DefaultTableModel> sorter;
Vector curRow;
ActionListener menuListener;
Writer out;
BufferedWriter bw;
File file;
JFileChooser chooser;
void printBill()
{
// bPrev.setValues(tBno.getText(), tDate.getText(), tCustomer.getText(), tTotal.getText(), tTotal2.getText(), tPrevBal.getText());
try
{
rs=db.stmt.executeQuery("select value from SETTINGS where property='shop'");
rs.next();
shop=rs.getString(1);
rs=db.stmt.executeQuery("select value from SETTINGS where property='address'");
rs.next();
address=rs.getString(1);
rs=db.stmt.executeQuery("select value from SETTINGS where property='owner'");
rs.next();
owner=rs.getString(1);
rs=db.stmt.executeQuery("select value from SETTINGS where property='contact'");
rs.next();
contact=rs.getString(1);
rs=db.stmt.executeQuery("select value from SETTINGS where property='sign'");
rs.next();
sign=rs.getString(1);
rs=db.stmt.executeQuery("select value from SETTINGS where property='savePath'");
rs.next();
destPath=rs.getString(1);
dtm = (DefaultTableModel) BillTbl.getModel();
file=new File(destPath+"Bill-"+tBno.getText()+".html");
out=new FileWriter(file);
bw=new BufferedWriter(out);
bw.write("<header><title> Bill-No "+tBno.getText()+"</title></head><body><p align=center> <b> "+shop+" </b><br> <b> पत्ता : </b> "+address+" <br> <b> मालक : </b> "+owner+" <br> <b> भ्रमणध्वनी क्र. </b> "+contact+" <br>--------------------------------------------</br> <b> बिलक्रमांक : </b> "+tBno.getText()+"         <b> दिनांक : </b> "+new SimpleDateFormat("dd-MM-YYYY").format(new java.util.Date())+" <br> <b> ग्राहकाचे नाव : </b> "+tCustomer.getText()+"    </p>");
bw.write("<center><table border=1><tr>");
for (int i=0;i<dtm.getColumnCount();i++)
{
if(i==0 || i==2 || i==4)
{
bw.write("<th>   "+dtm.getColumnName(i)+"   </th>");
}
}
bw.write("</tr>");
for (int i=0;i<dtm.getRowCount();i++)
{
bw.write("<tr>");
for (int j=0;j<dtm.getColumnCount();j++)
{
if(j==0)
{
bw.write("<td>   "+dtm.getValueAt(i,j).toString()+"   </td>");
}
else if(j==2 || j==4)
{
bw.write("<td align=center>"+dtm.getValueAt(i,j).toString()+"</td>");
}
}
bw.write("</tr>");
}
bw.write("</table><br><table border=0><tr><td rowspan=3><img src='"+sign+"' height=40 width=70></td><td align=right> रक्कम रू. "+tTotal.getText()+"/- </td></tr><tr><td align=right> देयक रक्कम रू. "+tPrevBal.getText()+"/- </td></tr><tr><td align=right> <b> एकूण रक्कम रू. "+tTotal2.getText()+"/- </b> </td></tr></table></center></body>");
bw.close();
Desktop.getDesktop().open(file);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}