如何实现JFrame的最小化功能。
比如我编写一个程序,点击一个按钮后,实现相应的功能并且程序最小化。
[CODE]
[/CODE]
[/CODE]import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SpringLayout;
import javax.swing.UIManager;
public class MinFrame extends JFrame {
private SpringLayout springLayout;
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
MinFrame frame = new MinFrame();
frame.setVisible(true);
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel") ;
frame.setExtendedState(frame.MAXIMIZED_BOTH);
} catch (Exception e) {
e.printStackTrace();
}
}
public final void min(){
this.setState(this.ICONIFIED);
}
/**
* Create the frame
*/
public MinFrame() {
super();
springLayout = new SpringLayout();
getContentPane().setLayout(springLayout);
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
min();
}
});
button.setText("最小化窗口");
getContentPane().add(button);
springLayout.putConstraint(SpringLayout.NORTH, button, 130, SpringLayout.NORTH, getContentPane());
springLayout.putConstraint(SpringLayout.WEST, button, 155, SpringLayout.WEST, getContentPane());
//
}
}