Java 最小化 最大化
发布网友
发布时间:2023-11-29 08:29
我来回答
共2个回答
热心网友
时间:2024-12-14 21:14
看看是不是这样的:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FrameDemo extends JFrame implements ActionListener{
JButton btn1;
JButton btn2;
public FrameDemo() {
this.setBounds(100, 100, 300, 200);
btn1 = new JButton("最小化");
btn2 = new JButton("最大化");
btn1.addActionListener(this);
btn2.addActionListener(this);
this.add(btn1, BorderLayout.CENTER);
this.add(btn2, BorderLayout.SOUTH);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn1) {
this.setExtendedState(JFrame.ICONIFIED);
} else if (e.getSource() == btn2) {
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
}
public static void main(String[] args) {
new FrameDemo();
}
}
热心网友
时间:2024-12-14 21:14
参考这个:
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);