Summary: I’m currently doing an applet laboratory exercise that simulates a taxi cab, it has to have a display of the speed, fuel, fare and distance traveled, also a marquee whether the cab is occupied or vacant. it has buttons that gives interaction to the user.
Problem: I used a thread for the fare, distance and fuel and another thread for the marquee, but why is it that my marquee blinks continuously?
Summary : I’m currently doing an applet laboratory exercise that simulates a taxi cab,
Share
Without code, it’s really anyone’s guess, but regardless I’ll take a stab. My guess is that you’re drawing directly in the JApplet’s
paint(...)method and thereby losing all possible gain from Swing’s double buffering. If so, then change this and draw in thepaintComponent(...)method of a JPanel that the JApplet is displaying.If this doesn’t help, then consider giving us enough information so that we don’t have to guess. You may want to fill us in on how you’re doing your threading and assure us that you’re careful to obey Swing threading rules and update Swing components on the event thread only.
Edit
Your code:
Yep, I guessed correctly: you’re painting directly in the JApplet. As I stated initially, don’t do that. In fact your best bet at learning to do this correctly is to read the tutorials:
You’ve also got a lot of other errors in your code, some significant, including using == to compare Strings rather than the
equals(...)orequalsIgnoreCase(...)method, and trying to callThread#stop()directly. Never do that. Also don’t set a component’s border within paint or paintComponent. Also you are setting a component’s text and background color from within a background thread and off of the Swing event thread — two potential causes of intermittent and hard to debug threading errors. You’ll only want to do these things on the Swing event thread.