OK, I'm trying to use the MouseListener for the first time, but I'm not fortunate enough. My program is fine, but masonleaster events do nothing. Here is my code:
Import java.awt.color. *; Import java.awt.font *; Import java.awt.Graphics; Import java.awt.Image; Import javax.swing *; Import java.awt.event.MouseEvent; Import java.awt.event.MouseListener; Public class yo applies MouseListener {image image; Jeffre Frame = New Gefram (); Jealous halo = new jlabell ("yo"); JPNL Panel = New JPNL () {@ Override Public Wide Paint Comonant (Graphics G) {// Superparents Companent (G); // Image Icon I = New Imagens ("hi.jpg"); // image = i.getImage (); //g.drawImage(image,150,150,null); //g.drawString("Hello")100,100); //g.drawString("Hi"//50,50); }}; Public yo () {frame.add (panel); Frame.setTitle ("hello"); Frame.setSize (500,500); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.setVisible (true); Frame.setLocationRelativeTo (zero); Panel.add (heloo); } Public Zero Mouseclat (Mouse Event Event) {Hello. Set text ("hi"); Println ("Hi"); } Public Zero MouseAut (Mouse Event Event) {System.out.println ("Hi")}} Public Zero Mousex (Mouse Event Event) {} Public Zero Mouse Mouse Pressed (Mouse Event Event) {} Public Zero Mouse Released (Mouse Event Event) {} Public static zero main (string [] args) {new yo (); }} By doing anything I mean that the system does not output text to command line or JLabel changes.
How to get it done will be great, thanks.
ps I am a Nob, good to be
Read the swing tutorial.
You did not add any component to the listener.
No comments:
Post a Comment