2012-08-22 3 views
-2

jsprame을 jsp에서 호출하는 방법을 알고 싶습니다. 브라우저에서 버튼을 클릭하면 프레임을 호출하려고합니다. 하지만 어떻게 해야할지 모르겠습니다. 광산이 아닌 경우 설명해주십시오.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은 애플릿을 확장하지 않습니다. – EJP

+0

아니요. 애플릿을 확장하고이 클래스에서 JFrame을 사용했습니다. public ** class LoadFromStore extends Applet ** 구현 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 비공개 JList lstCertificate = null; \t 개인 JLabel jLabel = null; \t 개인 JPasswordField 암호 = null; \t 개인 JButton btnLoad = null; \t 개인 JLabel jLabel1 = null; –

답변

2

브라우저에서 버튼을 클릭하면 프레임을 호출하려고합니다.

Java Web Start을 사용하여 HTML 링크 (또는 버튼)에서 직접 프레임을 실행하십시오.

관련 문제