java - Multiple image change on mouse hover over an image -


I have to get the solution for a Java program. As soon as the mouse cursor is over the box, I want to change the image in a rectangular box. After changing images in the box (at least 5 different images), the mouse is not on the images and the change stops because the cursor moves out of the box. I can only use the g I want to set up pictures

Please help me understand this problem because I am stuck.

This code will help you with some help Could! Import java.awt.Color; Import java.awt.Dimension; Import java.awt.Graphics; Import java.awt.Image; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Import java.awt.event.MouseAdapter; Import java.awt.event.MouseEvent; Import javax.imageio.ImageIO; Import javax.swing.BorderFactory; Import javax.swing.JFrame; Import javax.swing.JPanel; Import javax.swing.Timer; Public square response {/ ** * * / Private static last long serial VisserionUID = 1 L; Public reply () {JFrame frame = new JFrame (); Frame.getContentPane () Add (new rectangle); Frame.pack (); Frame.setVisible (true); } Public static zero main (string AGR []) {new answer (); } Public square rectangle extends to JPanel {/ ** * * / Private static last long serial VERSIONUID = 1 L; Image image; Timer timer; Int count = 0; Public Rectangle () {setBorder (BorderFactory.createMatteBorder (1, 1, 1, 1, color.black)); Setpriffred size (new dimension (100,100)); Timer = new timer (800, new exclamationist) {@ Override Public Voice Action Perforated (ActionArt RJX) {Loadpick (Count% 5); Count ++; Revise (); Coloring ();}}); AddMouseListener (New Mouse Adapter) {@Override Public Zero Molecule (MouseEvents Asbank) {count = 0; Timer.start ();} @ override public wide mousex (mouse events) {timer.stop ();}}); } @ Override Protected Zero Paint Comonant (Graphics G) {SuperPaintConant (G); G.drawImage (IMG, 0, 0, 120, 100, this); } Public Zero Loadopic (Int Number) {String Address = ""; Switch (number) {case 0: address = "img1.jpg"; break; Case 1: Address = "img2.jpg"; break; Case 2: Address = "img3.jpg"; break; Case 3: Address = "img4.jpg"; break; Default: address = "img5.jpg"; break; } Try {img = ImageIO.read (getClass (). GetResourceAsStream (address)); } Hold (exception e) {System.out.println ("Error loading picture"); }}}}


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -