?? mainframe.java
字號:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.text.*;
import javax.swing.text.*;
import java.sql.*;
//主窗體
class MainFrame implements MouseListener, ActionListener
{
//主窗體
JFrame frameMain;
Container cpMain;
//主窗體工具欄
JToolBar barMain;
JLabel[] lblTool=new JLabel[7];
//主窗體背景圖
JLabel lblImage;
//登陸窗口
JFrame dlFrame;
JDialog dialog;
JLabel[] lbl=new JLabel[2];
Choice choice;
JPasswordField pass;
JButton[] cmd=new JButton[2];
Container cp;
//系統設置
JPanel paneSystem,paneSys;
JLabel[] lblSystem=new JLabel[4];
//注冊用戶面板
JPanel paneZhuce;
JLabel[] lblZhuce=new JLabel[3];
JTextField[] txtZhuce=new JTextField[3];
JButton[] cmdZhuce=new JButton[2];
//刪除用戶面板
JPanel paneDel;
JLabel lblDel;
Choice choiceDel;
JButton[] cmdDel=new JButton[2];
//更改密碼面板
JPanel paneUpdate;
JLabel[] lblUpdate=new JLabel[3];
Choice choiceUpdate;
JTextField[] txtUpdate=new JTextField[3];
JButton[] cmdUpdate=new JButton[2];
//
JTextField[] txtTemp=new JTextField[4];
static int admi=1;
static String name;
//構造函數
MainFrame()
{
//主窗體工具欄初始化
barMain=new JToolBar();
barMain.setFloatable(false);
barMain.setBorder(null);
barMain.setBackground(new Color(255,255,240));
lblTool[0]=new JLabel("首頁");
lblTool[1]=new JLabel("企業");
lblTool[2]=new JLabel("人力");
lblTool[3]=new JLabel("就業");
lblTool[4]=new JLabel("統計");
lblTool[5]=new JLabel("系統");
lblTool[6]=new JLabel("關于");
for(int i=0;i<7;i++)
{
lblTool[i].setIcon(new ImageIcon("img/toolMain.gif"));
lblTool[i].setForeground(Color.blue);
lblTool[i].addMouseListener(this);//監聽
lblTool[i].setBorder(BorderFactory.createRaisedBevelBorder());
lblTool[i].setHorizontalTextPosition(SwingConstants.CENTER);
//工具欄加入組件
if(i==1||i==4)
barMain.addSeparator();
barMain.add(lblTool[i]);
}
//主窗體背景圖
lblImage=new JLabel();
lblImage.setIcon(new ImageIcon("img/main.jpg"));
//主窗體布局管理
frameMain=new JFrame("職業中介管理系統");
cpMain=frameMain.getContentPane();
cpMain.setLayout(new BorderLayout());
//主窗體加入組件
cpMain.add(barMain,BorderLayout.NORTH);
cpMain.add(lblImage,BorderLayout.CENTER);
//顯示主窗體
frameMain.setSize(800,570);
frameMain.show();
//系統登陸
dlFrame=new JFrame("登陸窗口");
dialog=new JDialog(dlFrame,true);
dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt)
{
int op=JOptionPane.showConfirmDialog(dialog,"確定要退出嗎?","提示",JOptionPane.YES_NO_OPTION);
if(op==JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
});
cp=dialog.getContentPane();
cp.setBackground(new Color(255,255,220));
cp.setLayout(new GridBagLayout());
lbl[0]=new JLabel("用戶名");
lbl[1]=new JLabel("密碼");
choice=new Choice();
setchoice(choice,"select * from 用戶 order by 用戶名 desc");
pass=new JPasswordField(8);
pass.setBackground(new Color(255,255,220));
pass.setBorder(BorderFactory.createMatteBorder(0,0,1,0,new Color(89,89,255)));
cmd[0]=new JButton("確定");
cmd[1]=new JButton("退出");
for(int i=0;i<2;i++)
{
lbl[i].setForeground(new Color(89,89,255));
cmd[i].addActionListener(this);
cmd[i].setForeground(new Color(89,89,255));
cmd[i].setBackground(new Color(255,255,220));
}
GridBagConstraints c=new GridBagConstraints();
c.insets=new Insets(8,0,8,8);
c.gridy=0;
cp.add(lbl[0],c);
cp.add(choice,c);
c.gridy++;
cp.add(lbl[1],c);
cp.add(pass,c);
c.gridy++;
cp.add(cmd[0],c);
c.anchor=GridBagConstraints.EAST;
cp.add(cmd[1],c);
dialog.setLocation(300,200);
dialog.pack();
dialog.show();
//系統設置面板
paneSystem=new JPanel();
paneSys=new JPanel();
paneSystem.setBackground(new Color(255,255,240));
paneSystem.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
lblSystem[0]=new JLabel("注冊用戶");
lblSystem[1]=new JLabel("修改密碼");
lblSystem[2]=new JLabel("刪除用戶");
lblSystem[3]=new JLabel("重新登陸");
for(int i=0;i<4;i++)
{
lblSystem[i].setFont(new Font("隸書",Font.BOLD,30));
lblSystem[i].setIcon(new ImageIcon("img/s.jpg"));
lblSystem[i].setForeground(new Color(128,0,255));
lblSystem[i].setHorizontalTextPosition(SwingConstants.CENTER);
lblSystem[i].addMouseListener(this);
lblSystem[i].setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
}
paneSystem.setLayout(new GridBagLayout());
GridBagConstraints cs=new GridBagConstraints();
cs.insets=new Insets(5,0,5,5);
cs.gridy=0;
paneSystem.add(lblSystem[0],cs);
paneSystem.add(lblSystem[1],cs);
cs.gridy++;
paneSystem.add(lblSystem[2],cs);
paneSystem.add(lblSystem[3],cs);
paneSys.setLayout(new BorderLayout());
paneSys.add(paneSystem,BorderLayout.CENTER);
////注冊用戶面板
paneZhuce=new JPanel();
paneZhuce.setBackground(new Color(255,255,240));
paneZhuce.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
lblZhuce[0]=new JLabel("用戶名");
lblZhuce[1]=new JLabel("密碼");
lblZhuce[2]=new JLabel("確認密碼");
for(int i=0;i<3;i++)
{
txtZhuce[i]=new JTextField(10);
lblZhuce[i].setForeground(new Color(128,0,255));
txtZhuce[i].setBorder(BorderFactory.createMatteBorder(0,0,1,0,Color.blue));
txtZhuce[i].setBackground(new Color(255,255,240));
}
cmdZhuce[0]=new JButton("確認");
cmdZhuce[1]=new JButton("返回");
for(int i=0;i<2;i++)
{
cmdZhuce[i].setBackground(new Color(255,255,240));
cmdZhuce[i].setForeground(Color.blue);
cmdZhuce[i].addActionListener(this);
}
paneZhuce.setLayout(new GridBagLayout());
GridBagConstraints cz=new GridBagConstraints();
cz.insets=new Insets(10,0,10,10);
cz.gridy=0;
paneZhuce.add(lblZhuce[0],cz);
paneZhuce.add(txtZhuce[0],cz);
cz.gridy++;
paneZhuce.add(lblZhuce[1],cz);
paneZhuce.add(txtZhuce[1],cz);
cz.gridy++;
paneZhuce.add(lblZhuce[2],cz);
paneZhuce.add(txtZhuce[2],cz);
cz.gridy++;
paneZhuce.add(cmdZhuce[0],cz);
cz.anchor=GridBagConstraints.EAST;
paneZhuce.add(cmdZhuce[1],cz);
//更改密碼面板
paneUpdate=new JPanel();
paneUpdate.setBackground(new Color(255,255,240));
paneUpdate.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
lblUpdate[0]=new JLabel("用戶名");
lblUpdate[1]=new JLabel("新密碼");
lblUpdate[2]=new JLabel("確認新密碼");
choiceUpdate=new Choice();
for(int i=0;i<3;i++)
lblUpdate[i].setForeground(new Color(128,0,255));
for(int i=0;i<2;i++)
{
txtUpdate[i]=new JTextField(10);
txtUpdate[i].setBorder(BorderFactory.createMatteBorder(0,0,1,0,Color.blue));
txtUpdate[i].setBackground(new Color(255,255,240));
}
cmdUpdate[0]=new JButton("確認");
cmdUpdate[1]=new JButton("返回");
for(int i=0;i<2;i++)
{
cmdUpdate[i].setBackground(new Color(255,255,240));
cmdUpdate[i].setForeground(Color.blue);
cmdUpdate[i].addActionListener(this);
}
paneUpdate.setLayout(new GridBagLayout());
GridBagConstraints cu=new GridBagConstraints();
cu.insets=new Insets(10,0,10,10);
cu.gridy=0;
paneUpdate.add(lblUpdate[0],cu);
paneUpdate.add(choiceUpdate,cu);
cu.gridy++;
paneUpdate.add(lblUpdate[1],cu);
paneUpdate.add(txtUpdate[0],cu);
cu.gridy++;
paneUpdate.add(lblUpdate[2],cu);
paneUpdate.add(txtUpdate[1],cu);
cu.gridy++;
paneUpdate.add(cmdUpdate[0],cu);
cu.anchor=GridBagConstraints.EAST;
paneUpdate.add(cmdUpdate[1],cu);
//刪除用戶面板
paneDel=new JPanel();
paneDel.setBackground(new Color(255,255,240));
paneDel.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
lblDel=new JLabel("用戶名");
lblDel.setForeground(new Color(128,0,255));
choiceDel=new Choice();
cmdDel[0]=new JButton("確認");
cmdDel[1]=new JButton("返回");
for(int i=0;i<2;i++)
{
cmdDel[i].setBackground(new Color(255,255,240));
cmdDel[i].setForeground(Color.blue);
cmdDel[i].addActionListener(this);
}
paneDel.setLayout(new GridBagLayout());
GridBagConstraints cd=new GridBagConstraints();
cd.insets=new Insets(10,0,10,10);
cd.gridy=0;
paneDel.add(lblDel,cd);
paneDel.add(choiceDel,cd);
cd.gridy++;
paneDel.add(cmdDel[0],cd);
cd.anchor=GridBagConstraints.EAST;
paneDel.add(cmdDel[1],cd);
/////////////
for(int i=0;i<4;i++)
{
txtTemp[i]=new JTextField(20);
txtTemp[i].setEditable(false);
txtTemp[i].setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.orange));
if(i%2==0)
txtTemp[i].setBackground(Color.orange);
else
txtTemp[i].setBackground(new Color(255,255,240));
}
paneSys.add(txtTemp[0],BorderLayout.NORTH);
paneSys.add(txtTemp[1],BorderLayout.WEST);
paneSys.add(txtTemp[2],BorderLayout.SOUTH);
paneSys.add(txtTemp[3],BorderLayout.EAST);
}
//set choice
void setchoice(Choice c,String str)
{
c.removeAll();
DataBase db=new DataBase();
db.GetResultSet(str);
try
{
while(db.rs.next())
c.addItem(db.rs.getString(1));
db.st.close();
}catch(SQLException e){}
}
//主程序入口
public static void main(String[] args)
{
new MainFrame();
}
public void mouseClicked(MouseEvent parm1)
{
// TODO: Add your code here
}
public void mousePressed(MouseEvent parm1)
{
//工具欄<<首頁>>標簽
if(parm1.getSource()==lblTool[0])
{
cpMain.removeAll();
cpMain.add(barMain,BorderLayout.NORTH);
cpMain.add(lblImage,BorderLayout.CENTER);
cpMain.setVisible(false);
cpMain.setVisible(true);
}
//工具欄<<企業>>標簽
if(parm1.getSource()==lblTool[1])
{
Factory factory=new Factory();
cpMain.removeAll();
cpMain.add(barMain,BorderLayout.NORTH);
cpMain.add(factory.pane,BorderLayout.CENTER);
cpMain.setVisible(false);
cpMain.setVisible(true);
}
////工具欄<<人力>>標簽
if(parm1.getSource()==lblTool[2])
{
People people=new People();
cpMain.removeAll();
cpMain.add(barMain,BorderLayout.NORTH);
cpMain.add(people.pane,BorderLayout.CENTER);
cpMain.setVisible(false);
cpMain.setVisible(true);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -