一,采用的是model2三层模型开发
一个为主界面,index ,一个为登录界面UserLogin
1、
package com.mol.view;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Index extends JWindow implements Runnable{
//定义为成员变量,将应用类型嵌入到Window窗口中!
paint p;
public static void main(String[] args) {
try {
// 将当前窗体外观设置为所在操作系统的外观
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
Index index = new Index();
Thread t = new Thread(index);
t.start();
}
//构造方法用来初始化变量和方法
public Index() {
// 创建P
p = new paint();
this.add(p);
this.setSize(400, 250);
// 确定Jwindow初始位置
this.setLocationRelativeTo(null);
this.setVisible(true);
}
//线程方法,跳出登录页面
public void run() {
while(true) {
try {
Thread.sleep(29*500);
} catch (Exception e) {
e.printStackTrace();
}
this.dispose();
//跳转到登录页面
new UserLogin();
break;
}
}
}
//定义一个闪屏类方法
class paint extends JPanel implements Runnable{// 可以自动刷新Panel
Thread t;
int x = 10;
int i = 0, j = 40, u = 10;
String gg[] = { “系”, “统”, “正”, “在”, “加”, “载”, “请”, “稍”, “侯” };
int k = 0, tt = 0;
String shi[] = { “满”, “汉”, “楼”, “融”, “满”, “汉”, “精”, “华”, “做”, “天”, “下”,
“美”, “味”, “招”, “八”, “方”, “食”, “客”, “结”, “四”, “海”, “良”, “朋”,
“满”, “汉”, “楼”, “程”, “序”, “演”, “示” };
Font f = new Font(“隶书”, Font.PLAIN, 18);
boolean ifok = true;
int width = 180;
int height = 0;
int dian = 0;
paint() {
t = new Thread(this);
t.start();
}
public void run() {
while (true) {
if (x <= 380);
repaint();
try {
Thread.sleep(70);
i++;// i=0
j = j - 6;// j=40
u = u + 10;// u=10
if (tt == 3)
width = width - 20; // tt=0,width=180
if (i == 4) {
tt++;
if (ifok && x > 120 + k * 20)
k++;// k=0
if (k >= gg.length - 1)
ifok = false;
x = x + 10;
i = 0;
j = 40;
u = 10;
dian++;
if (dian > 3)
dian = 0;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void paintComponent(Graphics g) {
// super.paintComponent(g);
Image image;
image = Toolkit.getDefaultToolkit().getImage("image/index.jpg");// 获得背景图片
g.drawImage(image, 0, 0, this.getWidth(), 200, this);
int r = (int) (Math.random() * 255);
int b = (int) (Math.random() * 255);
int y = (int) (Math.random() * 255);
g.setColor(new Color(253, 250, 250));// White
g.fillRect(x, 210, 380 - x, 30);
g.setColor(new Color(253, 250, 250));// white
if (i > 1)
g.fillRect(x, 235 - (j + 20) / 2, 10, j + 10);// 领头的长方块儿
if (j > 25)
g.setColor(new Color(r, b, y));
else
g.setColor(new Color(123, 194, 252));// light blue
g.fillRect(x, 235 - (j + 20) / 2, 10, j);// 后面跟着的短方块儿,10代表闪动条的宽度,j代表闪动条的高度
g.setColor(new Color(123, 194, 252));// light blue
g.drawRect(10, 210, 380, 30);
if (x < 120) {
for (int l = 0; l < gg.length; l++) {
g.setColor(new Color(0, 0, 0));
g.drawString(gg[l], 120 + l * 20, 230);
}
for (int l = 0; l < dian; l++) {
g.setColor(new Color(0, 0, 0));
g.drawString("*", 300 + l * 10, 235);
}
g.drawString("*", 300 + dian * 10, 235);
} else {
// 设置写字的颜色和位置
g.setColor(new Color(23, 23, 230));
g.drawString(gg[k], 120 + k * 20, 230);
for (int l = k + 1; l < gg.length; l++) {
g.setColor(new Color(0, 0, 0));
g.drawString(gg[l], 120 + l * 20, 230);
}
if (x > 300 + dian * 10)
g.setColor(new Color(23, 23, 230));
for (int l = 0; l < dian; l++) {
g.drawString("*", 300 + l * 10, 235);
}
g.drawString("*", 300 + dian * 10, 235);
}
// ------------逐字写诗
if (tt < 3) {
for (int rr = 0; rr <= tt; rr++) {
g.setColor(new Color(250, 0, 0));
g.drawString(shi[rr], 180, 60 + rr * 20);
}
g.drawString(shi[tt], 180, 60 + tt * 20);
}
if (tt >= 3 && tt < 8) {
g.setColor(new Color(230, 0, 0));
for (int rr = 0; rr < 3; rr++)
g.drawString(shi[rr], 180, 60 + rr * 20);
g.setColor(new Color(r, b, y));
if (tt < 8)
for (int rr = 3; rr <= tt; rr++)
g.drawString(shi[rr], 150, rr * 20);
if (tt >= 7)
for (int rr = 3; rr < 8; rr++)
g.drawString(shi[rr], 150, rr * 20);
}
if (tt >= 8 && tt < 13) {
g.setColor(new Color(230, 0, 0));
for (int rr = 0; rr < 3; rr++)
g.drawString(shi[rr], 180, 60 + rr * 20);
for (int rr = 3; rr <= 7; rr++)
g.drawString(shi[rr], 150, rr * 20);
g.setColor(new Color(r, b, y));
if (tt < 13)
for (int rr = 8; rr <= tt; rr++)
g.drawString(shi[rr], 120, rr * 20 - 100);
if (tt >= 13)
for (int rr = 8; rr < 13; rr++)
g.drawString(shi[rr], 120, rr * 20 - 100);
}
if (tt >= 13 && tt < 18) {
g.setColor(new Color(230, 0, 0));
for (int rr = 0; rr < 3; rr++)
g.drawString(shi[rr], 180, 60 + rr * 20);
for (int rr = 3; rr <= 7; rr++)
g.drawString(shi[rr], 150, rr * 20);
for (int rr = 8; rr < 13; rr++)
g.drawString(shi[rr], 120, rr * 20 - 100);
g.setColor(new Color(r, b, y));
if (tt < 18)
for (int rr = 13; rr <= tt; rr++)
g.drawString(shi[rr], 90, rr * 20 - 200);
if (tt >= 18)
for (int rr = 13; rr < 13; rr++)
g.drawString(shi[rr], 90, rr * 20 - 200);
}
if (tt >= 18 && tt < 23) {
g.setColor(new Color(230, 0, 0));
for (int rr = 0; rr < 3; rr++)
g.drawString(shi[rr], 180, 60 + rr * 20);
for (int rr = 3; rr <= 7; rr++)
g.drawString(shi[rr], 150, rr * 20);
for (int rr = 8; rr < 13; rr++)
g.drawString(shi[rr], 120, rr * 20 - 100);
for (int rr = 13; rr < 18; rr++)
g.drawString(shi[rr], 90, rr * 20 - 200);
g.setColor(new Color(r, b, y));
if (tt < 23)
for (int rr = 18; rr <= tt; rr++)
g.drawString(shi[rr], 60, rr * 20 - 300);
if (tt >= 23)
for (int rr = 18; rr < 23; rr++)
g.drawString(shi[rr], 60, rr * 20 - 300);
}
if (tt >= 23 && tt < 30) {
g.setColor(new Color(230, 0, 0));
for (int rr = 0; rr < 3; rr++)
g.drawString(shi[rr], 180, 60 + rr * 20);
for (int rr = 3; rr <= 7; rr++)
g.drawString(shi[rr], 150, rr * 20);
for (int rr = 8; rr < 13; rr++)
g.drawString(shi[rr], 120, rr * 20 - 100);
for (int rr = 13; rr < 18; rr++)
g.drawString(shi[rr], 90, rr * 20 - 200);
for (int rr = 18; rr < 23; rr++)
g.drawString(shi[rr], 60, rr * 20 - 300);
g.setColor(new Color(r, b, y));
if (tt < 30)
for (int rr = 23; rr <= tt; rr++)
g.drawString(shi[rr], 30, rr * 20 - 400);
if (tt >= 30) {
tt = 0;
for (int rr = 18; rr < 23; rr++)
g.drawString(shi[rr], 30, rr * 20 - 300);
}
}
if (tt > 30) {
g.setColor(new Color(230, 0, 0));
for (int rr = 0; rr < 3; rr++)
g.drawString(shi[rr], 180, 60 + rr * 20);
for (int rr = 3; rr <= 7; rr++)
g.drawString(shi[rr], 150, rr * 20);
for (int rr = 8; rr < 13; rr++)
g.drawString(shi[rr], 120, rr * 20 - 100);
for (int rr = 13; rr < 18; rr++)
g.drawString(shi[rr], 90, rr * 20 - 200);
for (int rr = 18; rr < 23; rr++)
g.drawString(shi[rr], 60, rr * 20 - 300);
for (int rr = 23; rr < 3//0; rr++)
g.drawString(shi[rr], 30, rr * 20 - 400);
}
}
}
/// // / ///
2
package com.mol.view;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.imageio.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.io.IOException;
public class UserLogin extends JDialog implements ActionListener{
//定义 需要的组件
JLabel jl1,jl2,jl3;
JTextField jName;
JPasswordField jPasswd;
JButton jConf,jCancel;
public static void main(String[] args) {
// TODO Auto-generated method stub
UserLogin ul = new UserLogin();
}
public UserLogin(){
//把一个组件放入到JFrame或者JDialog可以直接放
//也可以先放到Container,获取Jpanel面板内容getContentPane()存在ct上
Container ct=this.getContentPane();
//空局
this.setLayout(null);
//创建各个组件
jl1=new JLabel("请输入用户名:");
//setBounds 前两个是组件左上角在容器中的坐标。 (2)后两个是宽度和高度
jl1.setBounds(60, 190, 150, 30);
//jl1.setFont(MyTools.f1);
ct.add(jl1);
jName=new JTextField(20);
jName.setFocusable(true);
jName.setBounds(180, 190, 120, 30);
jName.setBorder(BorderFactory.createLoweredBevelBorder());//下凹
ct.add(jName);
jl2=new JLabel("(或员工号)");
jl2.setForeground(Color.red);//前景色
//jl2.setFont(MyTools.f2);
//setBounds 前两个是组件左上角在容器中的坐标。 (2)后两个是宽度和高度
jl2.setBounds(100, 210, 100, 30);
ct.add(jl2);
jl3=new JLabel("请输入 密 码:");
jl3.setBounds(60, 240, 150, 30);
ct.add(jl3);
jPasswd=new JPasswordField(20);
jPasswd.setBounds(180, 240, 120, 30);
jPasswd.setBorder(BorderFactory.createLoweredBevelBorder());
ct.add(jPasswd);
jConf=new JButton("确定");
jConf.setBounds(110, 300, 70, 30);
ct.add(jConf);
jCancel=new JButton("取消");
jCancel.setBounds(210, 300, 70, 30);
ct.add(jCancel);
//创建一个BackImage对象
BackImage bi=new BackImage();
//把位置确定
bi.setBounds(0, 0, 360, 360);
//不使用上下框
this.setUndecorated(true);
this.setSize(360, 360);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
//内部类
class BackImage extends JPanel{
Image im;
public BackImage(){
try {
im=ImageIO.read(new File("image/login.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void paintComponent(Graphics g){
g.drawImage(im, 0, 0, 360, 360, this);
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}