2012-08-22 64 views
-2

我想知道如何從jsp調用JFrame。 當我點擊瀏覽器上的按鈕時,我想調用框架。 但我不知道該怎麼辦。 如果你不是我的,請解釋我。如何從JSP調用JFrame?

這是一些代碼!

package testing; 

import javax.swing.JPanel; 
import javax.swing.JApplet; 
import javax.swing.JList; 
import java.awt.Rectangle; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.io.IOException; 
import java.security.Key; 
import java.security.KeyStore; 
import java.security.KeyStoreException; 
import java.security.NoSuchAlgorithmException; 
import java.security.PrivateKey; 
import java.security.UnrecoverableKeyException; 
import java.security.cert.Certificate; 
import java.security.cert.CertificateException; 
import java.security.cert.X509Certificate; 
import java.util.Enumeration; 
import java.util.Vector; 

import javax.swing.JLabel; 
import javax.swing.JPasswordField; 
import javax.swing.JButton; 

public class LoadFile extends JApplet implements ActionListener{ 

    private JPanel jContentPane = null; 
    private JList listCertificate = null; 
    private JLabel jLabel = null; 
    private JPasswordField password = null; 
    private JButton btnLoad = null; 
    private JLabel jLabel1 = null; 

    /** 
    * This is the xxx default constructor 
    */ 
    public LoadFile() { 
     super(); 
    } 

    /** 
    * This method initializes this 
    * 
    * @return void 
    */ 
    public void init() { 
     this.setSize(400, 306); 
     this.setContentPane(getJContentPane()); 
    } 

    /** 
    * This method initializes jContentPane 
    * 
    * @return javax.swing.JPanel 
    */ 
    private JPanel getJContentPane() { 
     if (jContentPane == null) { 
      jLabel1 = new JLabel(); 
      jLabel1.setBounds(new Rectangle(28, 19, 296, 30)); 
      jLabel1.setText("Choose your certificate"); 
      jLabel = new JLabel(); 
      jLabel.setBounds(new Rectangle(54, 228, 88, 26)); 
      jLabel.setText("Password"); 
      jContentPane = new JPanel(); 
      jContentPane.setLayout(null); 
      jContentPane.add(getListCertificate(), null); 
      jContentPane.add(jLabel, null); 
      jContentPane.add(getPassword(), null); 
      jContentPane.add(getBtnLoad(), null); 
      jContentPane.add(jLabel1, null); 
     } 
     return jContentPane; 
    } 

    /** 
    * This method initializes listCertificate 
    * 
    * @return javax.swing.JList  
    */ 
    private JList getListCertificate() { 
     if (listCertificate == null) { 
      listCertificate = new JList(); 
      listCertificate.setBounds(new Rectangle(26, 56, 345, 149)); 
      Vector<String> alias = getAlias(); 
      listCertificate.setListData(alias); 
     } 
     return listCertificate; 
    } 

    /** 
    * This method initializes password 
    * 
    * @return javax.swing.JPasswordField 
    */ 
    private JPasswordField getPassword() { 
     if (password == null) { 
      password = new JPasswordField(); 
      password.setBounds(new Rectangle(152, 224, 171, 28)); 
     } 
     return password; 
    } 

    /** 
    * This method initializes btnLoad 
    * 
    * @return javax.swing.JButton 
    */ 
    private JButton getBtnLoad() { 
     if (btnLoad == null) { 
      btnLoad = new JButton(); 
      btnLoad.setBounds(new Rectangle(189, 261, 70, 30)); 
      btnLoad.setText("Load"); 
      btnLoad.addActionListener(this); 
     } 
     return btnLoad; 
    } 


    public Vector<String> getAlias(){ 
     Vector<String> str = new Vector<String>(); 
     KeyStore ks; 
     try { 
      ks = KeyStore.getInstance("Windows-MY"); 
      ks.load(null, null); 
      Enumeration en = ks.aliases(); 
      String aliasName = ""; 
      while (en.hasMoreElements()) { 
       aliasName = (String) en.nextElement(); 
       str.add(aliasName); 
      } 

     } catch (KeyStoreException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (NoSuchAlgorithmException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (CertificateException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     return str; 
    } 

    @Override 
    public void actionPerformed(ActionEvent arg0) { 
     // TODO Auto-generated method stub 
     Object obj = arg0.getSource(); 
     if(obj == btnLoad){ 
      String alias = (String)getListCertificate().getSelectedValue(); 
      String password = getPassword().getText(); 

     } 
    } 

} // @jve:decl-index=0:visual-constraint="294,19" 

我想從JSP調用該類。 謝謝。

+5

JFrame不擴展Applet。 – EJP

+0

不,我擴展了Applet,並且在這個類中使用了JFrame。 public ** class LoadFromStore extends Applet ** implements ActionListener { \t private static final long serialVersionUID = 1L; \t ** private JFrame frame = null; ** // @jve:decl-index = 0:visual-constraint =「369,9」 \t private JPanel contentPane = null; \t private JList lstCertificate = null; \t private JLabel jLabel = null; \t private JPasswordField password = null; \t private JButton btnLoad = null; \t private JLabel jLabel1 = null; –

回答

2

當我點擊瀏覽器上的按鈕時,我想調用框架。

使用Java Web Start直接從HTML鏈接(或按鈕)啓動框架。