向高手请教。。。
请问我可以重写JFrame 窗体的 最大化, 最小化 和退出的按钮吗 ?
我想给退出的时候加个事件 !!
高手请教 最好有源代码
------解决方案--------------------可以。
调用 setUndecorated(true); 去掉自带的。
在右上角放置三个 JButton。
分别在点击时调用
setExtendedState(JFrame.ICONIFIED); // 最小
setExtendedState(JFrame.MAXIMIZED_BOTH); // 最大
dispose() or System.exit(0); //退出
------解决方案--------------------重画按钮?
还是自己写事件?
Java code
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
}
});
}
}
------解决方案--------------------
------解决方案--------------------
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();