confirmwindow.java

来自「图书馆的图书管理系统! 图书查询」· Java 代码 · 共 50 行

JAVA
50
字号
package labraryManager;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
public class ConfirmWindow extends JFrame implements ActionListener{
	public static final int WIDTH=200;
    public static final int HEIGHT=100;
    
    public ConfirmWindow(){
    	setSize(WIDTH,HEIGHT);
    	addWindowListener(new AnotherWindowDestroyer());
    	setTitle("图书管理系统");
    	Container x=getContentPane();
    	
    	x.setLayout(new BorderLayout());
    	JLabel z=new JLabel("确定退出?");
    	x.add(z,BorderLayout.CENTER);
    	JPanel y=new JPanel();
    	
    	y.setLayout(new FlowLayout());
    	JButton b1=new JButton("确定");
    	
    	
    	
    	b1.addActionListener(this);
    	y.add(b1);
    	JButton b2=new JButton("取消");
    	
    	b2.addActionListener(this);
    	y.add(b2);
    	x.add(y,BorderLayout.SOUTH);
    	
    }
    public void actionPerformed(ActionEvent e){
        if(e.getActionCommand().equals("确定"))
    		System.exit(0);
        else if(e.getActionCommand().equals("取消"))
    		dispose();
        
    	else
    		System.out.println("Error!");
    }
    private class AnotherWindowDestroyer extends WindowAdapter{
    	public void windowClosing(WindowEvent e){
        dispose();
        }
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?