public interface WindowStateListener extends EventListener { public void windowStateChanged(WindowEvent e); }
void
windowStateChanged(WindowEvent e)
Invoked
when window state is changed.
import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.*; import javax.swing.*; import java.awt.*; public class WindowStateListenerEx{ JTextArea displayArea; TextField typingArea; JFrame frame1; WindowStateListenerEx(){ /* Initialize typingArea */ typingArea = new TextField(20); /* Initialize Display Area */ displayArea = new JTextArea(); displayArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(displayArea); scrollPane.setPreferredSize(new Dimension(150, 200)); /* Initialize Frame */ frame1 =new JFrame("Sample Frame"); frame1.pack(); frame1.setVisible(true); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.getContentPane().add(typingArea, BorderLayout.PAGE_START); frame1.getContentPane().add(scrollPane, BorderLayout.CENTER); frame1.setSize(300, 500); frame1.addWindowStateListener(new WindowStateListener(){ public void windowStateChanged(WindowEvent e){ displayArea.append("Window State Changed\n"); } }); } public static void main(String args[]){ new WindowStateListenerEx(); } }
No comments:
Post a Comment