⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifyaccountframe.java

📁 java酒店管理系统
💻 JAVA
字号:
package myprojects.Account;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.event.*;
import java.util.*;
import javax.swing.table.*;
import java.io.*;
//-----------------导入自定义的包---------------------------
import myprojects.Account.*;

/**
 * @(#)LoginSetPanel.java
 *
 * 修改帐户信息:
 *  
 * @author 
 * @version 1.00 05/12/25
 */
 
public class ModifyAccountFrame extends JFrame {
  JPanel contentPane;
  JPanel accountInfoPanel = new JPanel();
  JLabel hintaccountInfoLabel = new JLabel();  
  JPanel buttonPanel = new JPanel();
  JButton modifyButton = new JButton();  
  JButton exitButton = new JButton();
    //用表格来表示列表
  DefaultTableModel accountInfoModel = new DefaultTableModel();
  JTable accountInfoTable = new JTable(accountInfoModel);
  
  ModifyAccount modifyAccount = new ModifyAccount();
  
  //Construct the frame
  public ModifyAccountFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(null);
    this.setSize(new Dimension(400, 350));
    this.setLocation(290,250);
    this.setTitle("修改帐户");
    this.setResizable(false); //使之不能改变大小
    contentPane.setForeground(Color.black);
    accountInfoPanel.setBackground(Color.lightGray);
    accountInfoPanel.setBounds(new Rectangle(24, 14, 345, 202));
    BorderLayout border = new BorderLayout();
    accountInfoPanel.setLayout(border);    
    
    hintaccountInfoLabel.setText("                  "+
    "                           帐户信息");   
     
    buttonPanel.setBackground(Color.lightGray);
    buttonPanel.setBounds(new Rectangle(24, 226, 347, 54));
    buttonPanel.setLayout(null);
    modifyButton.setBounds(new Rectangle(151-65, 16, 73, 25));
    modifyButton.setText("修改");   
    exitButton.setBounds(new Rectangle(245-40, 16, 73, 25));
    exitButton.setText("退出");
    contentPane.add(accountInfoPanel, null);
    accountInfoPanel.add(hintaccountInfoLabel,BorderLayout.NORTH);
    contentPane.add(buttonPanel, null);
    buttonPanel.add(modifyButton, null);   
    buttonPanel.add(exitButton, null);
    
    /////////////////////////////////////////////    	
    accountInfoModel.addColumn("帐号");    
    accountInfoModel.addColumn("类别");    
    accountInfoModel.addColumn("姓名");
    accountInfoModel.addColumn("性别");
    accountInfoModel.addColumn("工资");    
    
       			
    accountInfoTable.setPreferredScrollableViewportSize(new Dimension(130, 100));
    accountInfoTable.setBackground(new Color(255, 255, 210));    
    accountInfoTable.setRowHeight(20);
    accountInfoTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane reserveInfoscrollpane = new JScrollPane(accountInfoTable);
    accountInfoPanel.add(reserveInfoscrollpane,BorderLayout.CENTER); 
    
   
///////////////////////////////////////////// 
	//从 ModifyAccount 类型对象获取帐户信息
	Vector acclist = new Vector();
	Account account = new Account();			
	acclist = modifyAccount.accountList;
		
	for(int i=0;i<acclist.size();i++)
	{
		String accountClass="接待员";
		if(account.getAccountClass()==1){
			accountClass="管理员";
		}
		account=(Account)acclist.get(i);
		String sex="女";
		if(account.getAccountSex() == 1)
			sex="男";
		accountInfoModel.addRow(new Object[]{ 
		
						account.getAccountId().toString().trim(),
						accountClass,
						account.getAccountName().toString().trim(),
						sex,						
						Integer.toString(account.getAccountWage())								
				 		});	
	}		
    this.setVisible(true); 
    //按钮事件处理    
    modifyButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {		   
		   saveModifyAccountInfo_modifyButtonClick();		   
		}
	});	
	
	exitButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {		   
		   System.out.println("退出修改帐户信息界面");
		   closeFrame();				
		}
	});	
  }/////////////////// jbInit end

  
  void saveModifyAccountInfo_modifyButtonClick() {
  	 int index = accountInfoTable.getSelectedRow();
  	 System.out.println ("你选择了数组的位置为"+index);  
  	 //如果没有选中元素,则不作处理 
  	 if(index == -1) 
  	 	return ;
  	 ////////////////////////////////
  	 Account account = new Account(); 
  	 account=(Account)modifyAccount.accountList.get(index);  	 	 	 
  	 System.out.println ("将要修改的帐户信息为: ");
  	 account.printAccountInfo();
  	 	  	 	
  	 //生成一个新框架,用以修改帐号信息,跟新建框架一样
  	 ModifiedNewAccountInfoFrame modifiedAcc = new ModifiedNewAccountInfoFrame(account);  	 	
     	
  }
  //close this frame when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      closeFrame();
    }
  }
  void closeFrame() {
  	this.dispose();	
  } 
}

⌨️ 快捷键说明

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