java - swing - windowlistener -


If I am creating a square, and I will load the object of that class in my Jeffram (class is basically a button And the panel with the text objects, but it does not matter) that my public static is not instantaneous until the zero main (string [] AGR] (unless the code is under code), how do I get WindowListener and other listeners Will I add that to the Jeffra F it is not among the original group?

Usually when I have this issue, Eclipse tells me to make Jeffram or other object stable and call it universally, but I tried and I do not think it Works with an example of JFram.

I have read and on other tutorials, but I want a general answer to answer this specific question for my app, because I run it in a lot of < P> Thank you for anyone who can help or read!

is showing us that your current code makes it clear what you are trying to do But it seems as if you have a class that both represent your panel and it also includes your main method, but I do not recommend it because it's the structure of the application Obscures, though this is a popular technique in tutorials Because it enables each file to fit in one file.

A WindowListener represents any object that needs to respond to window events, i.e. the change in the position of the window (in this case a JFrame ) When it becomes active, the impression, etc. The listener is a graphical component but there is no need to do this.

Here is a very simple example which I hope will describe this concept. Let's represent a class with a type of panel that has a JLabel which will display the number of window events so far. This will also implement WindowListener so that these events can be reported and every time it may be that the counter increases.

You should be able to compile and run this code because it is, and then see counter changes if you minimize / maximize the window, click on the other window and so on.

  Import java.awt.event. *; Import javax.swing *; Public category TestPanel expands JPanel implemented WindowListener {Private JLabel label = new JLabel ("No Window Events Yet"); Private int new event = 0; Public TestPanel () {this.add (label);} Private Zero Update () {label.setText (string format ("% d event", numEvents)); } Public Zero Window Open (Window Event E) {numEvents ++; Updates(); } // ... Similar types of other window listener methods ...}   

Then, to instantiate one of our panels, we need a main program and it will be sent to a < Code> JFrame .

  import javax.swing. *; Public class main {public static zero main (string [] args) {SwingUtilities.invokeLater (new runnab) (public zero run) {createAndDisplayGui ();}}); } Private Static Voices and Displays () {Jeffre Frame = New Gefram ("Test Frame"); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); TestPanel Panel = New TestPanel (); Frame.add (panel); // Add the panel in frame frame as a component. AddWindowListener (panel); // Add the panel to the frame frame as a listener. (); // Out frame and frame frame size. SetView (true); // display the frame}}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -