:arrow:Estou implementado um teclado virtual, para preencher um campo senha, de uma tela de login.
:arrow:Este teclado virtual é um applet com vários botões, cada um possui um valor numérico de 0…9.
:arrow:Quando o usuário clicar em um determina botão, gostaria de enviar o valor a um campo “text” do html.
:arrow:Alguém saberia me explicar ou teria algum exemplo de como se deve implementar este applet.
Aqui esta descrito o código que estou tentando executar:
Applet implementada:
package br;
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.event.ActionEvent;
import netscape.javascript.JSObject;
public class TecladoView extends JApplet
{
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private JButton jButton3 = new JButton();
private JButton jButton4 = new JButton();
private JButton jButton5 = new JButton();
private JButton jButton6 = new JButton();
private JButton jButton7 = new JButton();
private JButton jButton8 = new JButton();
private JButton jButton9 = new JButton();
private JButton jButton10 = new JButton();
private JButton jButton11 = new JButton();
private JButton jButton12 = new JButton();
private JSObject jso;
public TecladoView(){
}
public void init() {
try {
jbInit();
} catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
// this é o Applet
jso = JSObject.getWindow (this);
this.getContentPane().setLayout(null);
jButton1.setText("0");
jButton1.setBounds(new Rectangle(5, 10, 50, 20));
jButton2.setText("1");
jButton2.setBounds(new Rectangle(55, 10, 50, 20));
jButton3.setText("2");
jButton3.setBounds(new Rectangle(105, 10, 50, 20));
jButton4.setText("3");
jButton4.setBounds(new Rectangle(155, 10, 50, 20));
jButton5.setText("4");
jButton5.setBounds(new Rectangle(205, 10, 50, 20));
jButton6.setText("5");
jButton6.setBounds(new Rectangle(255, 10, 55, 20));
jButton7.setText("6");
jButton7.setBounds(new Rectangle(5, 30, 50, 20));
jButton8.setText("7");
jButton8.setBounds(new Rectangle(55, 30, 50, 20));
jButton9.setText("8");
jButton9.setBounds(new Rectangle(105, 30, 50, 20));
jButton10.setText("9");
jButton10.setBounds(new Rectangle(155, 30, 50, 20));
jButton11.setText("10");
jButton11.setBounds(new Rectangle(205, 30, 50, 20));
jButton12.setText("Clear");
jButton12.setBounds(new Rectangle(255, 30, 65, 20));
jButton12.setForeground(Color.red);
this.getContentPane().add(jButton12, null);
this.getContentPane().add(jButton11, null);
this.getContentPane().add(jButton10, null);
this.getContentPane().add(jButton9, null);
this.getContentPane().add(jButton8, null);
this.getContentPane().add(jButton7, null);
this.getContentPane().add(jButton6, null);
this.getContentPane().add(jButton5, null);
this.getContentPane().add(jButton4, null);
this.getContentPane().add(jButton3, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jButton1, null);
}
public void paint (Graphics g)
{
super.paint(g);
}
private void jButton1_actionPerformed(ActionEvent e)
{
try {
jso.eval("alert('Beleza Funcionou, setando o valor do botão no campo senha.');");
jso.eval("setaSenha(" + jButton1.getText().toString() + ");");
}
catch (Exception exception) {
showStatus( "Javascript error: " + exception);
}
}
}
Página Html que carrega o Applet:
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>...:::Login Siosp:::...</title>
<SCRIPT LANGUAGE="JavaScript">
function setaSenha(btn_value)
{
var f = document.forms[0];
alert('Senha antes da Atribuição: ' + f.senha.value);
f.senha.value = btn_value;
alert('Senha depois da Atribuição: ' + f.senha.value);
}
</SCRIPT>
</head>
<body>
<form name="form">
<table align="center">
<tr>
<td class="titulo">
<font color="#000000"><b>Digite sua senha:</b></font>
</td>
</tr>
<tr>
<td>
<applet code="br.TecladoView.class" width="325" height="60"></applet>
</td>
</tr>
<tr>
<td align="center">
<b>Senha:<b/> <input type="TEXT" name="senha" size="20">
</td>
</tr>
<tr>
<td align="center">
<input type="SUBMIT" name="btnLogar" value="Logar">
</td>
</tr>
</table>
</form>
</body>
</html>
O Applet esta carregando corretamente sem nenhum erro,
mas não estou conseguindo setar o valor do botão clicado no campo senha da minha página.
Alguém poderia me explicar ???
Desde já agradeço.
)