主界面和字體,圖片設置類
Index.java
~~~
package cy.view;
import java.awt.*;
import javax.swing.*;
public class Index extends JWindow implements Runnable
{
JProgressBar jpb;//繪制進度條
JLabel jl1;
int width,height;
public static void main(String[] args)
{
Index index=new Index();
Thread t=new Thread(index);//啟動線程-進度條
t.start();
}
public Index()
{
jl1=new JLabel(new ImageIcon("image/index.gif"));
jpb=new JProgressBar();
jpb.setStringPainted(true);
jpb.setIndeterminate(false);
jpb.setBorderPainted(false);
jpb.setBackground(Color.darkGray);
this.add(jl1,BorderLayout.NORTH);
this.add(jpb,BorderLayout.SOUTH);
this.setSize(400,263);
width=Toolkit.getDefaultToolkit().getScreenSize().width;
height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(width/2-200,height/2-150);
this.setVisible(true);
}
@Override
public void run() {
int []progressValue={0,1,5,8,14,17,26,35,38,43,49,56,65,71,75,78,86,94,98,99,100};
for(int i=0;i<progressValue.length;i++)
{
try {
Thread.sleep(1000);
} catch (Exception e) {}
jpb.setValue(progressValue[i]);
}
new Login();//打開登錄頁面
this.dispose();//當前界面關閉
}
}
~~~
Login.java
~~~
package cy.view;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.*;
import cy.tool.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
//import cy.moxing.*;
public class Login extends JDialog /*implements ActionListener*/
{
JLabel jl1,jl2,jl3;//標簽
JTextField jname;//文本框
JPasswordField jpasswd;//密碼框
JButton jlog,jcancle;//按鈕
Font f1;
public static void main(String []args)
{
Login login=new Login();
}
public Login()
{
jl1=new JLabel("請輸入用戶名:");
jl1.setBounds(60, 190, 150, 30);
jl1.setFont(MyFont.f1);
this.add(jl1);
jl2=new JLabel("(或員工號)");
jl2.setForeground(Color.red);
jl2.setFont(MyFont.f2);
jl2.setBounds(100,210,100,30);
this.add(jl2);
jl3=new JLabel ("請輸入密碼:");
jl3.setBounds(60,240,150,30);
jl3.setFont(MyFont.f2);
this.add(jl3);
jname=new JTextField(20);
jname.setFocusable(true);//光標默認在這兒
jname.setBounds(180,190,120,30);
jname.setFont(f1);
this.add(jname);
jname.setBorder(BorderFactory.createLoweredBevelBorder());
jpasswd=new JPasswordField();
jpasswd.setFocusable(true);
jpasswd.setBounds(180,240,120,30);
this.add(jpasswd);
jpasswd.setBorder(BorderFactory.createLoweredBevelBorder());
jlog=new JButton("確 定");
//jlog.addActionListener(this);
jlog.setBounds(105,300,75,30);
jlog.setFont(f1);
jlog.setForeground(Color.blue);
this.add(jlog);
jcancle=new JButton("取 消");
//jcancle.addActionListener(this);
jcancle.setBounds(215,300,75,30);
jcancle.setFont(f1);
jcancle.setForeground(Color.blue);
this.add(jcancle);
this.setLayout(null);
BackImage bi=new BackImage();
bi.setBounds(0,0,360,360);
this.add(bi);
this.setUndecorated(true);
this.setSize(360, 360);
int width=getToolkit().getDefaultToolkit().getScreenSize().width;
int height=getToolkit().getDefaultToolkit().getScreenSize().height;
this.setLocation(width/2-200,height/2-200);
this.setVisible(true);
}
/* public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jlog)
{
// String userName=this.jname.getText().trim();
// String passwd=new String(this.jpasswd.getPassword());
// Moxing um=new Moxing();
// String zhiwei=um.checkUser(userName, passwd);
// if(zhiwei.equals("經理")||zhiwei.equals("管理員")||zhiwei.equals("主管"))
{
new Caozuo();
this.dispose();
}
// else
// {
// JOptionPane.showMessageDialog(this,"用戶名或密碼錯誤");
// }
}
else if(e.getSource()==jcancle)
{
this.dispose();
}
} */
}
class BackImage extends JPanel
{
Image im;
public BackImage()
{
try
{
im=ImageIO.read(new File("image/login.gif"));
}
catch(Exception e){}
}
public void paint(Graphics g)
{
g.drawImage(im,0,0,360,360,this);
}
}
~~~
Main.java
~~~
package cy.view;
import cy.tool.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.Timer;
import java.util.*;
import java.awt.event.*;
import javax.imageio.*;
import java.io.*;
//import com.sun.java.swing.plaf.windows.resources.windows;
public class Main extends JFrame /*implements ActionListener,MouseListener*/
{
Image titleIcon,timebg;
JMenuBar jmb;
JMenu jm1,jm2,jm3,jm4,jm5,jm6;
JMenuItem jmm1,jmm2,jmm3,jmm4,jmm5;
ImageIcon jm1_icon1,jm1_icon2,jm1_icon3,jm1_icon4,jm1_icon5;
JToolBar jtb;
JButton jb1,jb2,jb3,jb4,jb5,jb6,jb7,jb8,jb9,jb10;
JPanel jp1,jp2,jp3,jp4,jp5;
JPanel jp3_1,jp3_2,jp3_3,jp3_4,jp3_5,jp3_6,jp3_7;
ImagePanel jp1_imgPanel;
Image jp1_bg;
JLabel jp1_lab1,jp1_lab2,jp1_lab3,jp1_lab4,jp1_lab5,jp1_lab6,jp1_lab7,jp1_lab8;
JLabel jp2_lab1,jp2_lab2;
Image jp3_bg;
JLabel jp3_l1,jp3_l2,jp3_l3,jp3_l4,jp3_l5,jp3_l6,jp3_l7;
CardLayout cardjp2,cardjp3;
JSplitPane jsp1;
JLabel timeNow;
javax.swing.Timer t;
public static void main(String[] args)
{
Main cz=new Main();
}
public void initMenu()
{
jm1_icon1=new ImageIcon("image/jm1_icon1.jpg");
jm1_icon2=new ImageIcon("image/jm1_icon2.jpg");
jm1_icon3=new ImageIcon("image/jm1_icon3.jpg");
jm1_icon4=new ImageIcon("image/jm1_icon4.jpg");
jm1_icon5=new ImageIcon("image/jm1_icon5.jpg");
jm1=new JMenu("系統管理");
jm1.setFont(MyFont.f1);
jmm1=new JMenuItem("切換用戶",jm1_icon1);
jmm1.setFont(MyFont.f2);
jmm2=new JMenuItem("切換到收款界面",jm1_icon2);
jmm2.setFont(MyFont.f2);
jmm3=new JMenuItem("登陸管理",jm1_icon3);
jmm3.setFont(MyFont.f2);
jmm4=new JMenuItem("萬年歷",jm1_icon4);
jmm4.setFont(MyFont.f2);
jmm5=new JMenuItem("退出",jm1_icon5);
jmm5.setFont(MyFont.f2);
jm1.add(jmm1);
jm1.add(jmm2);
jm1.add(jmm3);
jm1.add(jmm4);
jm1.add(jmm5);
jm2=new JMenu("人事管理");
jm2.setFont(MyFont.f1);
jm3=new JMenu("菜單服務");
jm3.setFont(MyFont.f1);
jm4=new JMenu("報表統計");
jm4.setFont(MyFont.f1);
jm5=new JMenu("成本及庫房");
jm5.setFont(MyFont.f1);
jm6=new JMenu("幫助");
jm6.setFont(MyFont.f1);
jmb=new JMenuBar();
jmb.add(jm1);
jmb.add(jm2);
jmb.add(jm3);
jmb.add(jm4);
jmb.add(jm5);
jmb.add(jm6);
this.setJMenuBar(jmb);
}
public void initToolBar()
{
jtb=new JToolBar();
jtb.setFloatable(false);
jb1=new JButton(new ImageIcon("image/jb1.jpg"));
jb2=new JButton(new ImageIcon("image/jb2.jpg"));
jb3=new JButton(new ImageIcon("image/jb3.jpg"));
jb4=new JButton(new ImageIcon("image/jb4.jpg"));
jb5=new JButton(new ImageIcon("image/jb5.jpg"));
jb6=new JButton(new ImageIcon("image/jb6.jpg"));
jb7=new JButton(new ImageIcon("image/jb7.jpg"));
jb8=new JButton(new ImageIcon("image/jb8.jpg"));
jb9=new JButton(new ImageIcon("image/jb9.jpg"));
jb10=new JButton(new ImageIcon("image/jb10.jpg"));
jtb.add(jb1);
jtb.add(jb2);
jtb.add(jb3);
jtb.add(jb4);
jtb.add(jb5);
jtb.add(jb6);
jtb.add(jb7);
jtb.add(jb8);
jtb.add(jb9);
jtb.add(jb10);
this.add(jtb,BorderLayout.NORTH);
}
public void initAllPanel()
{
jp1=new JPanel(new BorderLayout());
try {
jp1_bg=ImageIO.read(new File("image/jp1_bg.jpg"));
} catch (Exception e) {}
Cursor myCursor=new Cursor(Cursor.HAND_CURSOR);
jp1_imgPanel=new ImagePanel(jp1_bg);
this.jp1_imgPanel.setLayout(new GridLayout(8,1));
jp1_lab1=new JLabel(new ImageIcon("image/label_1.gif"));
jp1_imgPanel.add(jp1_lab1);
jp1_lab2=new JLabel("人 事 管 理",new ImageIcon("image/label_2.jpg"),0);
jp1_lab2.setFont(MyFont.f4);
jp1_lab2.setCursor(myCursor);
jp1_lab2.setEnabled(false);
//jp1_lab2.addMouseListener(this);
jp1_imgPanel.add(jp1_lab2);
jp1_lab3=new JLabel("登 陸 管 理",new ImageIcon("image/label_3.jpg"),0);
jp1_lab3.setFont(MyFont.f4);
jp1_lab3.setCursor(myCursor);
jp1_lab3.setEnabled(false);
//jp1_lab3.addMouseListener(this);
jp1_imgPanel.add(jp1_lab3);
jp1_lab4=new JLabel("菜 譜 價 格",new ImageIcon("image/label_4.jpg"),0);
jp1_lab4.setFont(MyFont.f4);
jp1_lab4.setCursor(myCursor);
jp1_lab4.setEnabled(false);
//jp1_lab4.addMouseListener(this);
jp1_imgPanel.add(jp1_lab4);
jp1_lab5=new JLabel("報 表 統 計",new ImageIcon("image/label_5.jpg"),0);
jp1_lab5.setFont(MyFont.f4);
jp1_lab5.setCursor(myCursor);
jp1_lab5.setEnabled(false);
//jp1_lab5.addMouseListener(this);
jp1_imgPanel.add(jp1_lab5);
jp1_lab6=new JLabel("成本及庫房",new ImageIcon("image/label_6.jpg"),0);
jp1_lab6.setFont(MyFont.f4);
jp1_lab6.setCursor(myCursor);
jp1_lab6.setEnabled(false);
//jp1_lab6.addMouseListener(this);
jp1_imgPanel.add(jp1_lab6);
jp1_lab7=new JLabel("系 統 設 置",new ImageIcon("image/label_7.jpg"),0);
jp1_lab7.setFont(MyFont.f4);
jp1_lab7.setCursor(myCursor);
jp1_lab7.setEnabled(false);
//jp1_lab7.addMouseListener(this);
jp1_imgPanel.add(jp1_lab7);
jp1_lab8=new JLabel("動 畫 幫 助",new ImageIcon("image/label_8.jpg"),0);
jp1_lab8.setFont(MyFont.f4);
jp1_lab2.setCursor(myCursor);
jp1_lab8.setEnabled(false);
//jp1_lab8.addMouseListener(this);
jp1_imgPanel.add(jp1_lab8);
jp1.add(jp1_imgPanel);
jp4=new JPanel(new BorderLayout());
this.cardjp2=new CardLayout();
jp2=new JPanel(cardjp2);
jp2_lab1=new JLabel(new ImageIcon("image/jp2_left.jpg"));
//jp2_lab1.addMouseListener(this);
jp2_lab2=new JLabel(new ImageIcon("image/jp2_right.jpg"));
//jp2_lab2.addMouseListener(this);
jp2.add(jp2_lab1,"0");
jp2.add(jp2_lab2,"1");
this.cardjp3=new CardLayout();
jp3=new JPanel(cardjp3);
try {
jp3_bg=ImageIO.read(new File("image/jp3_5.jpg"));
} catch (Exception e1) {}
ImagePanel ip_jp3=new ImagePanel(jp3_bg);
jp3_l1=new JLabel(new ImageIcon("image/jp3_1.jpg"));
jp3_l2=new JLabel(new ImageIcon("image/jp3_2.jpg"));
jp3_l3=new JLabel(new ImageIcon("image/jp3_3.jpg"));
jp3_l4=new JLabel(new ImageIcon("image/jp3_4.jpg"));
jp3_l5=new JLabel(new ImageIcon("image/jp3_5.jpg"));
jp3_l6=new JLabel(new ImageIcon("image/jp3_6.jpg"));
jp3_l7=new JLabel(new ImageIcon("image/jp3_7.jpg"));
jp3_1=new JPanel();
jp3_1.add(jp3_l1);
jp3_2=new JPanel();
jp3_2.add(jp3_l2);
jp3_3=new JPanel();
jp3_3.add(jp3_l3);
jp3_4=new JPanel();
jp3_4.add(jp3_l4);
jp3_5=new JPanel();
jp3_5.add(jp3_l5);
jp3_6=new JPanel();
jp3_6.add(jp3_l6);
jp3_7=new JPanel();
jp3_7.add(jp3_l7);
jp3.add(ip_jp3,"0");
jp3.add(jp3_1,"1");
jp3.add(jp3_2,"2");
jp3.add(jp3_3,"3");
jp3.add(jp3_4,"4");
jp3.add(jp3_5,"5");
jp3.add(jp3_6,"6");
jp3.add(jp3_7,"7");
jp4.add(jp2,BorderLayout.WEST);
jp4.add(jp3,BorderLayout.CENTER);
jsp1=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,jp1,jp4);
jsp1.setDividerLocation(150);
jsp1.setDividerSize(0);
this.add(jsp1,BorderLayout.CENTER);
}
public void initJp5()
{
jp5=new JPanel();
jp5.setLayout(new BorderLayout());
//t=new Timer(1000,this);
//t.start();
timeNow=new JLabel(Calendar.getInstance().getTime().toLocaleString());
timeNow.setFont(MyFont.f3);
try {
timebg=ImageIO.read(new File("image/time_bg.jpg"));
} catch (Exception e) {}
ImagePanel ip1=new ImagePanel(timebg);
ip1.setLayout(new BorderLayout());
ip1.add(timeNow,BorderLayout.EAST);
jp5.add(ip1);
this.add(jp5,BorderLayout.SOUTH);
}
public Main()
{
try {
titleIcon=ImageIO.read(new File("image/title.gif"));
} catch (IOException e) {}
this.setIconImage(titleIcon);
this.setTitle("滿漢樓餐飲管理系統");
this.setFont(MyFont.f0);
this.initMenu();
this.initToolBar();
this.initAllPanel();
this.initJp5();
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setSize(width,height-32);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//@Override
/*public void actionPerformed(ActionEvent e)
{
this.timeNow.setText("當前系統時間:"+Calendar.getInstance().getTime().toLocaleString()+" ");
}
public void mouseClicked(MouseEvent e) {
if(e.getSource()==this.jp1_lab2)
{
this.cardjp3.show(jp3, "1");
}
else if(e.getSource()==this.jp1_lab3)
{
this.cardjp3.show(jp3, "2");
}
else if(e.getSource()==this.jp1_lab4)
{
this.cardjp3.show(jp3, "3");
}
else if(e.getSource()==this.jp1_lab5)
{
this.cardjp3.show(jp3, "4");
}
else if(e.getSource()==this.jp1_lab6)
{
this.cardjp3.show(jp3, "5");
}
else if(e.getSource()==this.jp1_lab7)
{
this.cardjp3.show(jp3, "6");
}
else if(e.getSource()==this.jp1_lab8)
{
this.cardjp3.show(jp3, "7");
}
else if(e.getSource()==jp2_lab1)
{
this.jsp1.setDividerLocation(0);
this.cardjp2.show(jp2,"1");
}
else if(e.getSource()==jp2_lab2)
{
this.jsp1.setDividerLocation(150);
this.cardjp2.show(jp2,"0");
}
}
public void mouseEntered(MouseEvent e) {
if(e.getSource()==this.jp1_lab2)
{
this.jp1_lab2.setEnabled(true);
}
else if(e.getSource()==this.jp1_lab3)
{
this.jp1_lab3.setEnabled(true);
}
else if(e.getSource()==this.jp1_lab4)
{
this.jp1_lab4.setEnabled(true);
}
else if(e.getSource()==this.jp1_lab5)
{
this.jp1_lab5.setEnabled(true);
}
else if(e.getSource()==this.jp1_lab6)
{
this.jp1_lab6.setEnabled(true);
}
else if(e.getSource()==this.jp1_lab7)
{
this.jp1_lab7.setEnabled(true);
}
else if(e.getSource()==this.jp1_lab8)
{
this.jp1_lab8.setEnabled(true);
}
}
public void mouseExited(MouseEvent e) {
if(e.getSource()==this.jp1_lab2)
{
this.jp1_lab2.setEnabled(false);
}
else if(e.getSource()==this.jp1_lab3)
{
this.jp1_lab3.setEnabled(false);
}
else if(e.getSource()==this.jp1_lab4)
{
this.jp1_lab4.setEnabled(false);
}
else if(e.getSource()==this.jp1_lab5)
{
this.jp1_lab5.setEnabled(false);
}
else if(e.getSource()==this.jp1_lab6)
{
this.jp1_lab6.setEnabled(false);
}
else if(e.getSource()==this.jp1_lab7)
{
this.jp1_lab7.setEnabled(false);
}
else if(e.getSource()==this.jp1_lab8)
{
this.jp1_lab8.setEnabled(false);
}
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e){}*/
}
~~~
MyFont.java
~~~
package cy.tool;
import java.awt.Font;
public class MyFont {
public static Font f0=new Font("宋體",Font.PLAIN,18);
public static Font f1=new Font("宋體",Font.PLAIN,16);
public static Font f2=new Font("宋體",Font.PLAIN,14);
public static Font f3=new Font("宋體",Font.PLAIN,15);
public static Font f4=new Font("宋體",Font.PLAIN,13);
}
~~~
ImagePanel.java
~~~
package cy.tool;
import java.awt.*;
import javax.swing.*;
import javax.imageio.*;
public class ImagePanel extends JPanel{
Image im;
public ImagePanel(Image im)
{
this.im=im;
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setSize(width,height);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);
}
}
~~~

- 書寫心得
- 基礎回顧
- 異常的處理
- equils方法
- 集合類
- ArrayList的遍歷和添加
- ArrayList的刪除插入
- 實例:食品庫存管理
- HashMap
- 集合類的區別和選擇
- 泛型和反射機制
- 圖形化用戶界面(GUI)
- JFrame容器
- 邊界布局管理器
- 流式布局管理器
- 網格布局管理器
- Jpanel面板
- 文本框和標簽
- 單選按鈕和復選按鈕
- 下拉列表框和滾動條
- 拆分窗口
- 聊天窗口
- 用戶登錄界面
- 記事本界面
- 線程
- 創建線程的方法
- 線程的優先級
- 線程的睡眠
- 線程的讓步與阻塞
- 買票問題
- 生產消費問題
- IO流
- 字符流
- 字節流
- 緩沖流
- 數據流傳輸
- 轉換流
- 空字符串區別
- Print流
- Object
- IO流補充
- 繪圖技術和事件處理機制
- 繪圖基礎-繪制圖形
- 繪圖基礎-繪制圖像
- 繪圖基礎-繪制文字
- 事件處理-事件監聽
- 事件處理-控件事件
- 事件處理-鍵盤事件
- 事件處理-鼠標事件
- 事件處理-窗口事件
- 記事本
- 坦克大戰
- 階段1
- 階段2
- 階段3
- 階段4
- 階段5
- 階段6
- 階段7
- 階段8
- 階段9
- 階段10
- 階段11
- 階段12
- 階段13
- 階段14
- SQL Server 2005
- 簡易學生管理系統
- 階段(1)-顯示
- 階段(2)-查詢
- 階段(3)-添加
- 階段(4)-刪除
- 階段(5)-修改
- 簡易餐飲管理系統
- 階段-01
- 階段-02
- 階段-03
- 階段-04
- Index.java
- Login.java
- Main.java
- MyFont.java
- ImagePanel.java
- Conn.java
- Moxing.java
- 網絡編程基礎
- 互發信息(1)-傳輸
- 互發信息(2)-互發
- 互發信息(3)-GUI
- 互發信息(4)-對象流
- 網絡聊天工具
- 階段--01--界面
- Server
- Index
- Client
- Login
- Chat
- List