Amigos, veja a classe que estou fazendo:
import com.sun.media.sound.Toolkit;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeListener;
import java.text.CollationElementIterator;
import javax.swing.Action;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/* Autor: Gilberto B. Terra Jr.
* TecladoVirtual.java
* Criado em 7 de Julho de 2006, 00:08
*/
public class TecladoVirtual extends JApplet{
public void init(){
initComponents();
}
private void initComponents() {
// ---------- CRIACAO DOS OBJETOS Swing. -----------
JPanel jpanel1 = new JPanel();
JPanel jpanel2 = new JPanel();
JPanel jpanel3 = new JPanel();
JLabel jlabel1 = new JLabel("Usu\u00e1rio: ");
JLabel jlabel2 = new JLabel("Senha.......: ");
JTextField txtUsuario = new JTextField();
JTextField txtSenha = new JPasswordField();
JButton sair = new JButton("Fechar");
JButton bt0 = new JButton("0");
JButton bt1 = new JButton("1");
JButton bt2 = new JButton("2");
JButton bt3 = new JButton("3");
JButton bt4 = new JButton("4");
JButton bt5 = new JButton("5");
JButton bt6 = new JButton("6");
JButton bt7 = new JButton("7");
JButton bt8 = new JButton("8");
JButton bt9 = new JButton("9");
//-------------- PROPRIEDADES DOS OBJETOS ---------------
jpanel1.setBackground(new Color(255,255,204));
jpanel1.setPreferredSize(new Dimension(10,70));
jpanel2.setLayout(GridLayout(2,2,0,5));
jpanel2.setBackground(new Color(255,255,204));
jpanel3.setBackground(new Color(255,255,255));
jpanel3.setPreferredSize(new Dimension(10,40));
sair.setBackground(Color(255,0,0));
sair.setForeground(Color(255,255,255));
txtSenha.setEditable(false);
bt0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt0ActionPerformed(e);
}
});
bt1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt1ActionPerformed(e);
}
});
bt2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt2ActionPerformed(e);
}
});
bt3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt3ActionPerformed(e);
}
});
bt4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt4ActionPerformed(e);
}
});
bt5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt5ActionPerformed(e);
}
});
bt6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt6ActionPerformed(e);
}
});
bt7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt7ActionPerformed(e);
}
});
bt8.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt8ActionPerformed(e);
}
});
bt9.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
bt9ActionPerformed(e);
}
});
sair.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sairActionPerformed(e);
}
});
// --------- ADICIONANDO ITENS AOS PAINEIS ------------
jpanel1.add(bt0);
jpanel1.add(bt1);
jpanel1.add(bt2);
jpanel1.add(bt3);
jpanel1.add(bt4);
jpanel1.add(bt5);
jpanel1.add(bt6);
jpanel1.add(bt7);
jpanel1.add(bt8);
jpanel1.add(bt9);
jpanel2.add(jlabel1);
jpanel2.add(jlabel2);
jpanel2.add(txtUsuario);
jpanel2.add(txtSenha);
jpanel3.add(sair);
getContentPane().add(jpanel1, BorderLayout.NORTH);
getContentPane().add(jpanel2, BorderLayout.CENTER);
getContentPane().add(jpanel3, BorderLayout.SOUTH);
Dimension screensize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screensize.width-252)/2 , (screensize.height-187)/2 ,252,187);
// ----------- METODOS DOS BOTOES ---------------
private void bt0ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt1ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt2ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt3ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt4ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt5ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt6ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt7ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt8ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void bt9ActionPerformed(ActionEvent event){
txtSenha.setText(txtSenha.getText() + ((JButton)event.getSource()).getText());
}
private void sairActionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "Mensagem Enviada.", "Applet Teclado Virtual.", JOptionPane.INFORMATION_MESSAGE);
}
}
}
Mas veja o erro que ele dá quando eu compilo:
C:\Terra\Developed\NetBeans_WEB\NetBeans_WEB\src\java\TecladoVirtual.java:160: illegal start of expression
private void bt0ActionPerformed(ActionEvent event){
C:\Terra\Developed\NetBeans_WEB\NetBeans_WEB\src\java\TecladoVirtual.java:203: ';' expected
}
2 errors
O que é isso?
)