¿Porque no me sale el programa en Java BlueJ?
Hola a todos, soy nuevo por aqui y tambien en la programacion asi que si estoy escribiendo algo muy basico, disculpen,pero,bueno,he estado siguiendo unos tutoriales muy buenos en youtube de programacion en java la cosa es que el tipo que hace los videotutoriales tiene Eclipse para programar, demasiado bueno por cierto, pero por ahora yo trabajo con bluej, y es un poco diferente, sobre todo con eso de los objetos y otras cosas, pero bueno este es el codigo de un programa que saque del videotutorial,es una ventana de chat (solo una interfaz) al meterle el KeyListener y apretar la tecla ENTER lanza el mensaje a otra area de texto (arriba), lo raro es que en BlueJ no lo corre, no he probado con Eclipse pero en el videotutorial si corre con el, y quiero imaginar que tambien en BlueJ se puede y espero tambien que me puedan decir si algo se me fue a la hora de copiar. Hay va el codigo:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import javax.swing.*;
public class VentanaChat extends JFrame implements ActionListener, KeyListener{
private JTextArea area;
private JScrollPane scroll;
private JTextField texto;
private JButton boton;
public VentanaChat(){
super("GridBagLayout");
this.setSize(400,400);
this.setDefaultCloseOperation(JFrame.EXIÂ…
this.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
area = new JTextArea();
scroll = new JScrollPane(area);
texto = new JTextField(20);
boton = new JButton("Enviar");
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
add(scroll,gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
add(texto,gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.NONE;
add(boton,gbc);
boton.addActionListener(this);
texto.addKeyListener(this);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==boton){
area.append(texto.getText()+"n");
texto.setText("");
}
}
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()){
case KeyEvent.VK_ENTER:
area.append(texto.getText()+"n");
texto.setText("");
break;
}
}
}
si de algo les sirve al compilar me dice que: cannot find symbol - class KeyEvent.Gracias por su ayuda, por cierto, esta genial el foro.
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import javax.swing.*;
public class VentanaChat extends JFrame implements ActionListener, KeyListener{
private JTextArea area;
private JScrollPane scroll;
private JTextField texto;
private JButton boton;
public VentanaChat(){
super("GridBagLayout");
this.setSize(400,400);
this.setDefaultCloseOperation(JFrame.EXIÂ…
this.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
area = new JTextArea();
scroll = new JScrollPane(area);
texto = new JTextField(20);
boton = new JButton("Enviar");
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
add(scroll,gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
add(texto,gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.NONE;
add(boton,gbc);
boton.addActionListener(this);
texto.addKeyListener(this);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==boton){
area.append(texto.getText()+"n");
texto.setText("");
}
}
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()){
case KeyEvent.VK_ENTER:
area.append(texto.getText()+"n");
texto.setText("");
break;
}
}
}
si de algo les sirve al compilar me dice que: cannot find symbol - class KeyEvent.Gracias por su ayuda, por cierto, esta genial el foro.