将小程序放入Web浏览器
|
我设计了一个小程序,该小程序显示在单独的Java窗口中(并且还会显示一个空白的Web浏览器窗口),但是我希望它可以在Web浏览器中显示。我对此一无所知。我应该更改JFrame还是其他内容?
我的代码如下:
Public class myApplet extends Applet implements ActionListener{
public JPanel createContentPane (){
System.out.println(\"1\");
// We create a bottom JPanel to place everything on.
JPanel totalGUI = new JPanel();
totalGUI.setLayout(null);
titleLabel = new JLabel(\"Login\");
totalGUI.add(titleLabel);
// Creation of a Panel to contain the JLabels
textPanel = new JPanel();
textPanel.setLayout(null);
totalGUI.add(textPanel);
// Usuario Label
usuarioLabel = new JLabel(\"User\");
textPanel.add(usuarioLabel);
// Password nuevo Label
passwordLabel = new JLabel(\"Password\");
passwordLabel.setHorizontalAlignment(4);
textPanel.add(passwordLabel);
// TextFields Panel Container
panelForTextFields = new JPanel();
panelForTextFields.setLayout(null);
totalGUI.add(panelForTextFields);
// Password viejo Textfield
usuarioField = new JTextField(8);
panelForTextFields.add(usuarioField);
// Password nuevo Textfield
passwordField = new JPasswordField(8);
panelForTextFields.add(passwordField);
// Button for Logging in
loginButton = new JButton(\"Restore\");
loginButton.addActionListener(this);
totalGUI.add(loginButton);
totalGUI.setOpaque(true);
return totalGUI;
}
public void actionPerformed(ActionEvent e) {
//restores password
}
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame(\"Change password\");
myApplet demo = new myApplet ();
frame.setContentPane(demo.createContentPane());
frame.setSize(310, 400);
frame.setVisible(true);
}
public void init (){
System.out.println(\"Applet initializing\");
final myApplet rp = new myApplet ();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
rp.createAndShowGUI();
}
});
}
}
没有找到相关结果
已邀请:
3 个回复
郡晒景沧
跑步
久纳禾澎
并将控件直接放在
实例(
)中。
藕挝