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 から呼び出したい。ありがとう。