What do I need to do when I close a JFRm then set up a variable? There is a thread in my project. I want this thread to be run only if there is a fixed variable set in another class on the right. This is the class in which I will set the variable (the slider disabled):
import java.awt.Container; Import java.awt.Dimension; Import java.awt.Toolkit; Import javax.swing.JFrame; Import javax.swing.JSlider; Import javax.swing.event.ChangeEvent; Import javax.swing.event.ChangeListener; Public Class ZoomSlider JFrame Implemented ChangeListener {Private Static Last Long Serial VERSIONUID = -9026587156796382276L; Private JSlider Slider; Private Static Boolean Slider Active = Incorrect; Public Zoom Slider () {// setSliderActivated (true); Container content page = getContentPane (); This.setTitle ("zoom"); This.setDefaultCloseOperation (JFrame.HIDE_ON_CLOSE); This.setAlwaysOnTop (right); Toolkit mioToolkit = Toolkit.getDefaultToolkit (); Dimension dimensioniSchermo = mioToolkit.getScreenSize (); Int larghezzaFrame, altezzaFrame; Hattheffam = 80; AltezzaFrame = (int) (dimensioniSchermo.getHyight () - 70); This.setSize (larghezzaFrame, altezzaFrame); This.setLocation (0, 50); Slider = new JSlider (JSlider.VERTICAL, 50, 200, 100); Slider.setMajorTickSpacing (50); Slider.setMinorTickSpacing (10); Slider.setPaintTicks (true); Slider.setPaintLabels (true); Slider.addChangeListener (this); ContentPane.add (slider); This.setVisible (true); } @ Override Public Wide State Change (// setSliderActivated); Int value = ((JSlider) arg0.getSource ()). GetValue (); EarthPanel.SSCALE = Value / 100.0; // setSliderActivated (incorrect); } Public Stabilized Boolean Slider Active (active) {return slider; } Public Static Zero SetSlider Active (Boolean Slider Active) {ZoomSlider.sliderActivated = sliderActivated; }}
And this is the thread that runs the variable:
Public runs zero () {while (true) {if (ZoomSlider.isSliderActivated ()) {this.setPreferredSize (new dimension (int) (width * scale), (int) (height * scale)); Repaint (); }}}
I think that the redesign the main panel (the code is not present in this question) only when the JFrame ZoomSlider.java is visible in that moment, the slider will be activated, Will be set to the right. Instead, when I close the JFram, the slider will be activated and the thread will stop running. How can I do this?
Actually, you have to add WindowListener to the Geoffram, which responds to the events of closing or closing For:
jFrame.addWindowListener (New Window Adapter) {@Override Public Zero Window Closed (WindowEndE) {// Some] @ Override Public Zero Window Closing (WindowEvent e) { // do something } });
Comments
Post a Comment