• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

enableEvents() and processEvent() not found error?

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the code i was trying it gives compile time error that enableEvents() and processEvent() method not found in class Component.pls correct the code
//
import java.awt.*;
import java.awt.event.*;
class k56
{
static Frame frm;
public static void main(String args[])
{
frm=new Frame("user Frame");
frm.setBounds(25,25,400,400);
frm.setLayout(new FlowLayout());
((Component)frm).enableEvents(AWTEvent.WINDOW_EVENT_MASK | AWTEvent.KEY_EVENT_MASK); //Error
frm.setVisible(true);
}
public void processEvent(AWTEvent evt)
{
if(evt.getID()==WindowEvent.WINDOW_CLOSING)
{
frm.dispose();
System.exit(0);
}
if(evt.getID()==KeyEvent.KEY_TYPED && ((KeyEvent)evt).getKeyChar()=='q' && ((KeyEvent)evt).isControlDown())
{
frm.dispose();
System.exit(0);
}
((Component)frm).processEvent(evt);//Error
}
}
//
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The errors are:
k56.java:14: enableEvents(long) has protected access in java.awt.Component
((Component)frm).enableEvents(AWTEvent.WINDOW_EVENT_MASK | AWTEvent.KEY_EVENT_MASK); //Error
^
k56.java:33: processEvent(java.awt.AWTEvent) has protected access in java.awt.Component
((Component)frm).processEvent(evt);//Error
^
2 errors
The problem is that you can't override proteccted methods. You have to write this so that k56 extends Frame. try this:
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic