请问我可以重写JFrame 窗体的 最大化, 最小化 和退出的按钮吗 ? 
我想给退出的时候加个事件 !!
高手请教 最好有源代码 

解决方案 »

  1.   

    不行吧,那些都是native的。window里可以隐掉title,自己做。但是有些linux的会强制加上他们自己的title的。
      

  2.   

    不用重写也可以加事件啊,你看看api文档.......有相应的接口的...你实现了就行了.....
      

  3.   

    可以。调用 setUndecorated(true); 去掉自带的。
    在右上角放置三个 JButton。分别在点击时调用
    setExtendedState(JFrame.ICONIFIED); // 最小
    setExtendedState(JFrame.MAXIMIZED_BOTH); // 最大
    dispose() or System.exit(0); //退出
      

  4.   

    重画按钮?
    还是自己写事件?
    class Test extends JFrame {
    public Test() {
    this.addWindowListener(new WindowListener() { @Override
    public void windowActivated(WindowEvent arg0) {
    // TODO Auto-generated method stub

    } @Override
    public void windowClosed(WindowEvent arg0) {
    // TODO Auto-generated method stub

    } @Override
    public void windowClosing(WindowEvent arg0) {
    // TODO Auto-generated method stub

    } @Override
    public void windowDeactivated(WindowEvent arg0) {
    // TODO Auto-generated method stub

    } @Override
    public void windowDeiconified(WindowEvent arg0) {
    // TODO Auto-generated method stub

    } @Override
    public void windowIconified(WindowEvent arg0) {
    // TODO Auto-generated method stub

    } @Override
    public void windowOpened(WindowEvent arg0) {
    // TODO Auto-generated method stub

    }

    });
    }
    }
      

  5.   

    package view;import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPasswordField;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    import javax.swing.WindowConstants;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import bean.User;
    import db.UserDAO;
    public class Login extends javax.swing.JFrame implements ActionListener{
      
    private static final long serialVersionUID = 1L;
    private JLabel jLabel1;  
        private JLabel jLabel2;  
        private JPasswordField txtpassword;   
        private JButton btnCanel;  
        private JButton btnOK;  
        private JTextField txtuser;   
      
        public Login() {  
            super();  
            initGUI();  
        }  
    //初始化界面   
        private void initGUI() {  
            try {  
                setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);  
                getContentPane().setLayout(null);  
                {  
                    jLabel1 = new JLabel();  
                    getContentPane().add(jLabel1);  
                    jLabel1.setText("\u7528\u6237\u540d:");  
                    jLabel1.setBounds(79, 106, 42, 15);  
                }  
                {  
                    jLabel2 = new JLabel();  
                    getContentPane().add(jLabel2);  
                    jLabel2.setText("\u5bc6  \u7801:");  
                    jLabel2.setBounds(79, 140, 42, 15);  
                }  
                {  
                 txtuser = new JTextField();  
                    getContentPane().add(txtuser);  
                    txtuser.setBounds(144, 103, 153, 22);  
                }  
                {  
                 txtpassword = new JPasswordField();  
                    getContentPane().add(txtpassword);  
                    txtpassword.setBounds(144, 137, 153, 22);  
                }  
                {  
                    btnOK = new JButton();  
                    getContentPane().add(btnOK);  
                    btnOK.setText("\u8fdb\u5165");  
                    btnOK.setBounds(103, 178, 60, 22);  
                    btnOK.addActionListener(this);  
      
                }  
      
                {  
                    btnCanel = new JButton();  
                    getContentPane().add(btnCanel);  
                    btnCanel.setText("\u9000\u51fa");  
                    btnCanel.setBounds(202, 178, 60, 22);
                    btnCanel.addActionListener(this);
                }  
                pack();  
                this.setSize(400, 300);  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
        
    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    Login inst = new Login();
    inst.setLocationRelativeTo(null);
    inst.setVisible(true);
    }
    });
    } public void actionPerformed(ActionEvent e) {


    if(e.getSource().equals(btnOK)){
    // System.out.println("d2");

    User user = new User();
    user.setUsername(txtuser.getText());
    char ps[] = txtpassword.getPassword();
    String psd = new String(ps);
    user.setPassword(psd);

    UserDAO userdao = new UserDAO();
    String flag = userdao.queryAllEmp(user);
    if(flag.equals("YES")) {
    System.out.println("登录成功");
    CourseFrame inst = new CourseFrame();
    inst.setLocationRelativeTo(null);
    inst.setVisible(true);
    this.dispose();
    }else{
    JOptionPane.showMessageDialog(this, "用户名或密码不正确!!!");
    txtpassword.setText("");
    }
    }else if(e.getSource().equals(btnCanel)) {
    System.exit(0);
    }
    }
    }例子自己看去,
    btnOK.addActionListener(this);  添加监听事件
    e.getSoure()获得事件
    自己研究去
    至于最大最小,自己翻看API
      

  6.   

    不行吧,那些都是native的。window里可以隐掉title,自己做。但是有些linux的会强制加上他们自己的title的。