kungouf
Messages postés29Date d'inscriptionlundi 3 mai 2004StatutMembreDernière intervention15 février 2005
-
13 sept. 2004 à 11:54
kungouf
Messages postés29Date d'inscriptionlundi 3 mai 2004StatutMembreDernière intervention15 février 2005
-
13 sept. 2004 à 17:24
bonjour j'ai un probleme au niveau de la compilation de mon code qui dois detecter le clic sur un element graphique que j'ai cree ( des rectangles issus de la classe Rectan ), voici les erreurs de compilations:
j'ai un probleme d'abstract, et je suis un peu perdu
MainTest.java:10: MainTest is not abstract and does not override abstract method
awt.event.WindowListener
public class MainTest extends JFrame implements WindowListener, ActionListener,
^
MainTest.java:33: cannot resolve symbol
symbol : method addActionListener (Rectan)
location: class Rectan
rec1.addActionListener(rec1);
^
MainTest.java:34: cannot resolve symbol
symbol : method addActionListener (Rectan)
location: class Rectan
rec2.addActionListener(rec2);
^
MainTest.java:46: cannot resolve symbol
symbol : variable rec1
location: class MainTest
if ( (Rectan) e.getSource() == rec1 )
^
MainTest.java:48: cannot resolve symbol
symbol : variable rec2
location: class MainTest
if ( (Rectan) e.getSource() == rec2 )
^
5 errors
voici le code:
public class MainTest extends JFrame implements WindowListener, ActionListener, MouseListener, MouseMotionListener
{
public JLabel BarrePosition;
public MainTest(){
super("creation d'elements");
BarrePosition = new JLabel();
getContentPane().add(BarrePosition, BorderLayout.SOUTH);
setSize(500, 500);
show();
}
public void paint(Graphics g){
Rectan rec1 = new Rectan(5, 10, 100, 50);
Rectan rec2 = new Rectan(115, 10, 100, 50);
if ( (Rectan) e.getSource() == rec1 )
BarrePosition.setText("Presse sur element rec1");
if ( (Rectan) e.getSource() == rec2 )
BarrePosition.setText("Presse sur element rec2");
}
public static void main(String args[]){
MainTest app = new MainTest();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
toffe12
Messages postés53Date d'inscriptionvendredi 12 septembre 2003StatutMembreDernière intervention23 septembre 20051 13 sept. 2004 à 13:33
bonjour, lorsque tu declare implement un listener du doit definir dans ton programme toutes les methode des differents listeners implementés. Dans le code ci dessus tu n'a implemente que les methode de actionListener ( actionperformed()) si cela te suffit supprime les autres listeners de ta definition de classes comme suit
public class MainTest extends JFrame implements ActionListener
si tu as besoin des autres listeners declare les methodes associées
windowsListener :
void windowActivated(WindowEvent e)
Invoked when the Window is set to be the active Window.
void windowClosed(WindowEvent e)
Invoked when a window has been closed as the result of calling dispose on the window.
void windowClosing(WindowEvent e)
Invoked when the user attempts to close the window from the window's system menu.
void windowDeactivated(WindowEvent e)
Invoked when a Window is no longer the active Window.
void windowDeiconified(WindowEvent e)
Invoked when a window is changed from a minimized to a normal state.
void windowIconified(WindowEvent e)
Invoked when a window is changed from a normal to a minimized state.
void windowOpened(WindowEvent e)
Invoked the first time a window is made visible
mouselistener :
void mouseClicked(MouseEvent e)
Invoked when the mouse button has been clicked (pressed and released) on a component.
void mouseEntered(MouseEvent e)
Invoked when the mouse enters a component.
void mouseExited(MouseEvent e)
Invoked when the mouse exits a component.
void mousePressed(MouseEvent e)
Invoked when a mouse button has been pressed on a component.
void mouseReleased(MouseEvent e)
mousemotionlistener:
void mouseDragged(MouseEvent e)
Invoked when a mouse button is pressed on a component and then dragged.
void mouseMoved(MouseEvent e)
Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.