• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applet to com(excel) communication

 
Raghuveer Rawat
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I am trying to connect my applet with com componet (excel) using JIntegra a third party component.
I am deploying this application in tomcatjboss server.it is deployed succefully and I can see my applet in the Browser.
applet and html code are as follows:
import java.awt.*;
import com.linar.jintegra.AuthInfo;
//import com.linar.jintegra.*;
import java.awt.Button;
import java.awt.Label;
import java.awt.event.*;
import java.util.Date;

public class ExcelExampleApplet extends java.applet.Applet {
private TextField domainFld = new TextField(10);
private TextField userFld = new TextField(10);
private TextField passwordFld = new TextField(10);
private Button connectBtn = new Button("Connect");
private TextArea textArea = new TextArea(100, 800);
public void init()
{
// Begins tracking of created objects in that thread.
com.linar.jintegra.Cleaner.trackObjectsInCurrentThread();
// A Simple GUI to let the user enter Authentication information, connect to the
// server, and see the results.
setLayout(new GridLayout(2, 1));
Panel authPanel = new Panel();
authPanel.setLayout(new GridLayout(4, 2));
authPanel.add(new Label("Domain"));
authPanel.add(domainFld);
authPanel.add(new Label("User"));
authPanel.add(userFld);
authPanel.add(new Label("Password"));
passwordFld.setEchoCharacter('*');
authPanel.add(passwordFld);
authPanel.add(connectBtn);
connectBtn.addActionListener(new ButtonHandler());
//System.out.println("Button Handler Added");
add(authPanel);
add(textArea);
validate();

}
// Called when the user clicks on the Connect button

class ButtonHandler implements ActionListener
{

public void actionPerformed(ActionEvent e)
{
//String s = e.getActionCommand();
System.out.println("inside button handler");
if(e.getActionCommand().equals("Connect"))
{
doExcelExample();
}
}
}

private void doExcelExample()
{

try {
String host = getCodeBase().getHost();
System.out.println("host :"+host);
String domain = domainFld.getText().trim();
System.out.println("domain :"+domain);
String user = userFld.getText().trim();
System.out.println("user :"+user);
String password = passwordFld.getText();
System.out.println("password :"+password);
if (domain.length() != 0) {
AuthInfo.setDefault(domain, user, password);
}
// Create an instance of Excel.Application on the remote host
System.out.println("Connecting to " + host);
excel.Application app = new excel.Application(host);
System.out.println("Created an instance of Excel");
// Use Excel objects to get at a range in the displayed Worksheet
excel.Workbooks workbooks = app.getWorkbooks();
excel.Workbook workbook = workbooks.add(null);
excel.Sheets worksheets = workbook.getWorksheets();
excel.Worksheet sheet = new excel.Worksheet(worksheets.add(null, null, null, null));
excel.Range range = sheet.getRange("A1:C3", null);
app.setVisible(true); // Nice to see what is happening
System.out.println("Made Excel visible");
// New contents for the range -- notice the standard Java types
Object[][] newValue = {
{ "defe", new Boolean(false), new Double(98765.0 / 12345.0) },
{ new Date(), new Integer(5454), new Float(22.0 / 7.0) },
{ new Boolean(true), "dffe", new Date() }
};
range.setValue(newValue); // Update the spreadsheet
System.out.println("Updated the range ... sleeping for ten seconds");
Thread.sleep(10000); // Sleep 10 seconds -- maybe you want to change a value in the spreadsheet
// Get the new content of the range
Object[][] values = (Object[][]) range.getValue();
// Print them out. Again, the values are standard Java types
for(int i = 0; i < values.length; i++) {
for(int j = 0; j < values[i].length; j++) {
System.out.print(values[i][j] + "\t");
}
}
System.out.println("");
workbook.close(new Boolean(false), null, null); // False="=" don't prompt to save changes
app.quit();
System.out.println("Closed Excel down");
} catch(Exception e) {
System.out.println("Caught exception: " + e);
if(e instanceof SecurityException) {
throw (SecurityException)e;
}
} finally {
com.linar.jintegra.Cleaner.releaseAllInCurrentThread();
}
}
}
<HTML><HEAD><TITLE>J-Integra Applet Example</TITLE></HEAD>
<BODY>
<object code=ExcelExampleApplet.class width=500 height=250 archive="jintegra.jar,excel.jar">
</object>
</BODY>
</HTML>
My problem is when I click on the Connect button doExcelExample() method should be called but it is not called.
I am unable to trace the problem. can someone help me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic