Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By Fubarable
  • 1 Post By fauzeddd-

Thread: 'project' is not abstract and does not override abstract method keyPressed ...

  1. #1
    fauzeddd- is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Exclamation 'project' is not abstract and does not override abstract method keyPressed ...

    Hi guys, I'm certainly newbie at java...I was trying to add a method to a TextField in order to limit its length..
    Unfortunately, when I compile my project it shows me an error:

    Java Code:
    ProjectAlgorit is not abstract and does not override abstract method keyPressed(java.awt.event.KeyEvent) in java.awt.event.KeyListener
    Does anyone could help me?...I'm about to go off...I'll appreciate it so much guys

    Here is my code so far...

    Java Code:
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.applet.*;
    import java.util.*;
    import java.util.GregorianCalendar; 
    import java.util.Calendar;
    import java.text.*;
    import java.text.*;
    
    
    public class ProjectAlgorit extends JApplet implements ActionListener, KeyListener {
    	// Declaración de variables
    	
    	
    	
    	String usuario="Admin",password="daniel";
    	String xOk="0";
    	//####################PESTAÑAS################
    	
    	JTabbedPane	pstPrincipal;
    	
    	//##### 	PANEL INGRESO	################
    	JPanel 		pnlIngreso;
    	JLabel 		lblUser,lblPass,lblFondo;
    	JTextField 	txtUser;
    	JPasswordField txtPass;
    	JButton		btnIngresar;
    	ImageIcon imgPrincipal=new ImageIcon("Fondo.png");
    	
    	//#######	PANEL PRINCIPAL	#######################################
    	
    	JPanel pnlPrincipal;  	
    	JButton btnMante,btnRegist,btnConfig,btnImp,btnReport;	
    	
    
    	
    	//1######	PANEL MANTENIMIENTO	###################################
    	JPanel pnlMante;
    	JButton btnMant_Consult,btnMant_Modif,btnMant_List,
    	btnMant_Salir;
    	
    	//1.1######	PANEL MANTE-CONSULTAR EMPLEADO	#######################
    	JPanel pnlMante_ConsultaEmp;
    	JComboBox cboConsEmp_codEmp;
    	JLabel lblConsEmp_codEmp,lblConsEmp_nomYap,lblConsEmp_DNI;
    	JTextField txtConsEmp_nomYap,txtConsEmp_DNI;
    	JButton btnConsEmp_cargar,btnConsEmp_Salir;
    	
    	//1.2######	PANEL MANTE-MODIFICAR EMPLEADO	#######################
    	JPanel pnlMante_ModificarEmp;
    	JComboBox cboModEmp_codEmp;
    	JTextField txtModEmp_nomYap,txtModEmp_DNI;
    	JButton btnModEmp_cargar,btnModEmp_Grabar,btnModEmp_Salir;
    	
    	//1.3###### PANEL MANTE-LISTAR EMPLEADO	###########################
    	JPanel pnlMante_ListarEmp;
    	JButton btnListEmp_listar,btnListEmp_Salir;
    	JTextArea txtListEmp_S;
    	JScrollPane scp_ListEmp_Scroll;
    	
    	
    	
    	//2######	PANEL REGISTRO DE CONFECCIONES	#######################
    	JPanel pnlRegConf;
    	JComboBox cboReg_Cod,cboReg_TipoPrenda;
    	JLabel lblReg_cod,lblReg_tipoPrenda;
    	JTextField txtReg_cant;
    	JTextArea txtReg_S;
    	JScrollPane scp_Reg_Scroll;
    	JButton btnReg_efectuar,btnReg_salir;
    		
    	//3###### PANEL CONFIGURACION DE TARIFAS	###############################	
    	JPanel pnlConfTar;	
    	JButton btnConf_Guardar,btnConf_Salir;
    	JTextField txtConf_tarCamisa,txtConf_tarCasaca,txtConf_tarPanta;
    	JLabel lblConf_TCamisa,lblConf_TCasaca,lblConf_TPantalon;
    	
    		
    	//4######	PANEL IMPRESION DE BOLETA	###########################
    	JPanel pnlImpreBol;		
    	JComboBox cboImpre_codEmpleado;
    	JLabel lblImpre_codEmp;
    	JButton btnImpre_Generar,btnImpre_Salir;
    	
    		
    	//5#######	PANEL REPORTES	#######################################
    	JPanel pnlReport;	
    	JComboBox cboReport_tipoReport;
    	JLabel lblReport_tipoReport;
    	JButton btnReport_ver,btnReport_Salir;
    	JTextArea txtReport_S;
    	JScrollPane scp_Report_Scroll;	
    	//--------------------------------------------------------------------------
    	// Crea la interfaz gráfica de usuario	
    	public void init() {
    		
    		getContentPane().setLayout(null);
    		
    		// ======================================================================
            // * JPanel pnlPrincipal
            // ======================================================================
    		
    		pnlIngreso= new JPanel();
    		pnlIngreso.setLayout(null);
    		pnlIngreso.setBackground(new Color(118,87,0));
    		pnlIngreso.setBounds(0,0,800,600);
    		pnlIngreso.setVisible(true);
    		getContentPane().add(pnlIngreso);
    		
    		lblUser=new JLabel("Usuario: ");
    		lblUser.setBounds(300,320,90,23);
    		pnlIngreso.add(lblUser);
    		
    		txtUser= new JTextField();
    		txtUser.setBounds(390,320,140,23);
    		pnlIngreso.add(txtUser);
    		
    		lblPass= new JLabel("Password: ");
    		lblPass.setBounds(300,350,90,23);
    		pnlIngreso.add(lblPass);
    		
    		txtPass= new JPasswordField();
    	
    		txtPass.setBounds(390,350,140,23);
    		txtPass.addKeyListener(this);
    		pnlIngreso.add(txtPass);
    		
    		btnIngresar= new JButton("Ingresar");
    		btnIngresar.setBounds(390,380,120,25);
    		btnIngresar.addActionListener(this);
    		pnlIngreso.add(btnIngresar);
    		
    		lblFondo=new JLabel(new ImageIcon(getClass().getResource("Fondo.png")));
    		lblFondo.setIcon(imgPrincipal);
    		lblFondo.setBounds(0,0,800,600);
    		pnlIngreso.add(lblFondo);
    		
    		
    		// ======================================================================
            // * JPanel pnlPrincipal
            // ======================================================================
    		pnlPrincipal= new JPanel();
    		pnlPrincipal.setLayout(null);
    		pnlPrincipal.setBounds(0,0,700,400);
    		pnlPrincipal.setVisible(false);
    		pnlPrincipal.setBackground(Color.pink);
    		getContentPane().add(pnlPrincipal);
    				
    		
    			
    				
    				//1 boton Mantenimiento
    		btnMante=new JButton("Mantenimiento");
    		btnMante.setBounds(80,77,200,23);
    		btnMante.addActionListener(this);
    		pnlPrincipal.add(btnMante);
    		
    				//1.1 Panel Mantenimiento
    		pnlMante=new JPanel();
    		pnlMante.setLayout(null);
    		pnlMante.setBounds(0,0,700,400);
    		pnlMante.setVisible(false);
    		pnlMante.setBackground(Color.yellow);
    		getContentPane().add(pnlMante);
    		
    		//boton consultar empleado del panel mantenimiento
    		btnMant_Consult= new JButton("Consultar empleado");
    		btnMant_Consult.setBounds(80,77,200,23);
    		btnMant_Consult.addActionListener(this);
    		pnlMante.add(btnMant_Consult);
    		
    		//1.1.1 Panel Mantenimiento: Consultar empleado
    		pnlMante_ConsultaEmp=new JPanel();
    		pnlMante_ConsultaEmp.setLayout(null);
    		pnlMante_ConsultaEmp.setBounds(0,0,700,400);
    		pnlMante_ConsultaEmp.setVisible(false);
    		pnlMante_ConsultaEmp.setBackground(new Color(120,56,112));
    		getContentPane().add(pnlMante_ConsultaEmp);
    		
    		//labelCOD del mantenimiento consultar empleado
    		lblConsEmp_codEmp=new JLabel("Código de empleado  :");
    		lblConsEmp_codEmp.setBounds(70,77,150,23);
    		pnlMante_ConsultaEmp.add(lblConsEmp_codEmp);
    		
    		//ComboBox del mantenimiento consultar empleado
    		cboConsEmp_codEmp=new JComboBox();
    		cboConsEmp_codEmp.setBounds(200,77,150,23);
    		pnlMante_ConsultaEmp.add(cboConsEmp_codEmp);
    		
    		//labelNOM del mantenimiento consultar empleado
    		lblConsEmp_nomYap=new JLabel("Nombres y apellidos  :");
    		lblConsEmp_nomYap.setBounds(70,101,150,23);
    		pnlMante_ConsultaEmp.add(lblConsEmp_nomYap);
    		
    		//TextBoxNOM del mantenimiento consultar empleado
    		txtConsEmp_nomYap=new JTextField();
    		txtConsEmp_nomYap.setBounds(200,101,300,23);
    		txtConsEmp_nomYap.setEnabled(false);
    		pnlMante_ConsultaEmp.add(txtConsEmp_nomYap);
    		
    		//labelDNI del mantenimiento consultar empleado
    		lblConsEmp_DNI=new JLabel("DNI  :",JLabel.RIGHT);
    		lblConsEmp_DNI.setBounds(70,125,124,23);
    		pnlMante_ConsultaEmp.add(lblConsEmp_DNI);
    		
    		//TextBoxDNI del mantenimiento consultar empleado
    		txtConsEmp_DNI=new JTextField();
    		txtConsEmp_DNI.setBounds(200,125,150,23);
    		txtConsEmp_DNI.setEnabled(false);
    		pnlMante_ConsultaEmp.add(txtConsEmp_DNI);
    		
    		//ButtonSALIR del mantenimiento consultar empleado
    		btnConsEmp_Salir=new JButton("Salir");
    		btnConsEmp_Salir.setBounds(200,150,120,23);
    		btnConsEmp_Salir.addActionListener(this);
    		pnlMante_ConsultaEmp.add(btnConsEmp_Salir);
    		
    		//boton modificar empleado del panel mantenimiento
    		btnMant_Modif=new JButton("Modificar empleado");
    		btnMant_Modif.setBounds(80,101,200,23);
    		btnMant_Modif.addActionListener(this);
    		pnlMante.add(btnMant_Modif);
    		
    		//boton listar empleado del panel mantenimiento
    		btnMant_List=new JButton("Listar empleado");
    		btnMant_List.setBounds(80,125,200,23);
    		btnMant_List.addActionListener(this);
    		pnlMante.add(btnMant_List);
    		
    		//boton salir del panel mantenimiento
    		btnMant_Salir=new JButton("Salir");
    		btnMant_Salir.setBounds(80,149,200,23);
    		btnMant_Salir.addActionListener(this);
    		pnlMante.add(btnMant_Salir);
    		
    				
    		
    				//2 boton Registro de confecciones
    		btnRegist=new JButton("Registro de confecciones");
    		btnRegist.setBounds(80,101,200,23);
    		btnRegist.addActionListener(this);
    		pnlPrincipal.add(btnRegist);
    		
    		
    				//3 boton Configuracion de tarifas
    		btnConfig=new JButton("Configuración de tarifas");
    		btnConfig.setBounds(80,125,200,23);
    		btnConfig.addActionListener(this);
    		pnlPrincipal.add(btnConfig);		
    		
    		
    				//4 boton Impresion de boletas
    		btnImp=new JButton("Impresión de boletas");
    		btnImp.setBounds(80,149,200,23);
    		btnImp.addActionListener(this);
    		pnlPrincipal.add(btnImp);
    		
    		
    				//5 boton Salir
    		btnReport=new JButton("Reportes");
    		btnReport.setBounds(80,173,200,23);
    		btnReport.addActionListener(this);
    		pnlPrincipal.add(btnReport);
    		
    		
    
    	}
    	//--------------------------------------------------------------------------
    	// Procesa eventos de tipo ActionEvent
    	
    
    
    	public void actionPerformed( ActionEvent e ){
    		
    		if (e.getSource()==txtPass || e.getSource()==btnIngresar){
    			
    			
    			ValidarUsuario();
    			if (xOk.equals("1")){	//muestra el siguiente panel si la variable xOk es igual a 1		
    			pnlIngreso.setVisible(false);
    			pnlPrincipal.setVisible(true);
    			}
    			
    		}
    		
    		if(e.getSource()==btnMante){
    			pnlPrincipal.setVisible(false);
    			pnlMante.setVisible(true);
    		}
    		
    		if(e.getSource()==btnMant_Consult){
    		//	pnlPrincipal.setVisible(false);
    			pnlMante.setVisible(false);			
    			pnlMante_ConsultaEmp.setVisible(true);
    		}
    		
    		if(e.getSource()==btnMant_Salir){
    			pnlMante.setVisible(false);
    			pnlPrincipal.setVisible(true);
    		}
    		
    		if(e.getSource()==btnConsEmp_Salir){
    	//		pnlPrincipal.setVisible(false);
    			pnlMante_ConsultaEmp.setVisible(false);
    			pnlMante.setVisible(true);
    		}
    
    	}
    	
    	void ValidarUsuario(){
    		
    		
    
    			String user=txtUser.getText();
    			String pass=txtPass.getText();
    			
    			if (user.equals("")){
    				JOptionPane.showMessageDialog(null,"Ingrese usuario");
    				return;
    			}
    			else if(pass.equals("")){
    				JOptionPane.showMessageDialog(null,"Ingrese password");
    				return;
    			}
    		
    		if (user.equals(usuario) && pass.equals(password)){
    			JOptionPane.showMessageDialog(null,"Bienvenido "+usuario);
    			xOk="1";  //toma el valor de 1 si se llega a logear sin problemas
    		}
    		else 		
    			JOptionPane.showMessageDialog(null,"Verifique usuario o contraseña");
    			pnlIngreso.setVisible(true);
    			pnlPrincipal.setVisible(false);
    		
    		//la variable xOk sigue con valor predeterminado 0
    					
    	}
    	
    
    
    
    
    
    public void keyTyped(KeyEvent e){
    	
    	 int limite  = 8;
    	
    	if (txtPass.getText().length()== limite)
    
         e.consume();
    }
    
    public void keyReleased(KeyEvent e){} // ignore
    
    		
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: 'project' is not abstract and does not override abstract method keyPressed ...

    Your class implements the KeyListener interface but doesn't have all the methods that this interface requires it to have. Any class that implements an interface must have all the methods of the interface; it's as simple as that. The error in fact tells you exactly what method you're missing.

    Myself, I try to avoid having my GUI's implement listener interfaces as it makes the GUI do too much. Instead consider using an anonymous inner class or other interface-specific class. I also try to avoid using KeyListeners with Swing applications in general.
    fauzeddd- likes this.

  3. #3
    fauzeddd- is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: 'project' is not abstract and does not override abstract method keyPressed ...

    Quote Originally Posted by Fubarable View Post
    Any class that implements an interface must have all the methods of the interface; it's as simple as that. The error in fact tells you exactly what method you're missing.
    Thanks a lot man! ...I'll consider that from now on.
    Fubarable likes this.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: 'project' is not abstract and does not override abstract method keyPressed ...

    You're welcome!

Similar Threads

  1. Replies: 4
    Last Post: 04-14-2011, 11:42 AM
  2. Replies: 4
    Last Post: 02-19-2011, 04:32 AM
  3. Replies: 3
    Last Post: 08-13-2010, 04:57 AM
  4. Replies: 3
    Last Post: 09-16-2009, 09:27 PM
  5. Replies: 2
    Last Post: 11-21-2008, 12:20 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •