你好我写了一些代码我虽然它会工作但它编译并且它甚至不会抛出异常或任何东西。它还创建了打开的图标,但我点击它并没有做任何事情请需要帮助才能知道我做错了什么。继承人的类的代码:
package practicagraficos8;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ventanatexto {
public JFrame ventana;
public String texto;
ventanatexto(){
JFrame.setDefaultLookAndFeelDecorated(true);
texto="";
ventana= new JFrame("teclado");
panel1 panel= new panel1();
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.add(panel);
ventana.setVisible(true);
ventana.addKeyListener(new handler());
}
public class panel1 extends JPanel {
@Override
public void paint(Graphics g){
super.paint(g);
Dimension dim= getSize();
g.clearRect(0, 0, dim.width, dim.height);
g.drawString(texto, WIDTH, WIDTH);
};
}
class handler extends KeyAdapter{
@Override
public void keyPressed(KeyEvent k){
char tecla= k.getKeyChar();
switch(tecla){
case 127:texto="";
break;
case 8: if(texto.length()>0){texto=texto.substring(0, texto.length()-1);}
break;
default:
if (texto.length()<15){texto+=tecla;}
}
ventana.repaint();
}
}}
这是我的主要内容:
package practicagraficos8;
public class Practicagraficos8 {
public static void main(String[] args) {
ventanatexto prueba= new ventanatexto();
}
}