重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
您好,提问者:
成都创新互联长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为定陶企业提供专业的网站建设、成都网站建设,定陶网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。
1、可以在电脑下载成功后,用USB连接手机,放进去。
2、可以使用手机自带的浏览器进行下载,直接可下载到手机上。
3、别人下载,蓝牙传到你手机上。
4、在电脑上下载,用读卡器
辽主临轩的分享
分享
java程序模拟qq登录界面的代码
java程序如何实现登录、记住密码、自动登录等功能!
package dyno.swing.beans.qq;
import javax.swing.*;
import javax.swing.event.MouseInputListener;
import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;
/*import org.jvnet.substance.skin.SubstanceModerateLookAndFeel;
import org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel;*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
public class QQLogin extends JFrame implements MouseInputListener,ActionListener{
JLabel guanggao,beijing,wenzi,shezhi,zhanghaowb,qq1,dengluzhuangtai;
// JTextField zhanghao;
JPopupMenu haoma;
JComboBox zhanghao;
JPasswordField mima;
JCheckBox jizhumima,zidongdenglu;
JButton denglu,chashamuma;
JProgressBar jpb;
SimThread activity;
Timer activityMonitor;
String name,qq;
Socket s;
public QQLogin()
{
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
chashamuma = new JButton("查杀木马");
chashamuma.setBounds(240, 155,85, 20);
this.add(chashamuma);
jpb = new JProgressBar();
jpb.setStringPainted(true);
jpb.setBounds(100, 240, 200, 15);
this.add(jpb);
chashamuma.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jpb.setMaximum(1000);//设置进度栏的最大值
activity=new SimThread(1000);
activity.start();//启动线程
activityMonitor.start();//启动定时器
chashamuma.setEnabled(false);//禁止按钮
}
});
activityMonitor=new Timer(100,new ActionListener(){//每0.5秒执行一次
public void actionPerformed(ActionEvent e){//以下动作将在事件调度线程中运行,十分安全
int current=activity.getCurrent();//得到线程的当前进度
jpb.setValue(current);//更新进度栏的值
if(current==activity.getTarget()){//如果到达目标值
activityMonitor.stop();//终止定时器
chashamuma.setEnabled(true);//激活按钮
}
}
});
dengluzhuangtai = new JLabel(new ImageIcon("zaixianzhuangtai.jpg"));
dengluzhuangtai.setBounds(75, 145, 35, 30);
this.add(dengluzhuangtai);
dengluzhuangtai.addMouseListener(this);
denglu = new JButton("登录");
denglu.setBounds(140, 155, 80, 20);
this.add(denglu);
this.setAlwaysOnTop(true);
zidongdenglu = new JCheckBox("自动登录");
zidongdenglu.setBounds(200, 190, 100, 30);
this.add(zidongdenglu);
jizhumima = new JCheckBox("记住密码");
jizhumima.setBounds(100, 190, 100, 30);
// jizhumima.setBackground(new Color(228, 244, 255));
this.add(jizhumima);
haoma = new JPopupMenu();
/* zhanghao = new JTextField(20);
zhanghao.setBounds(120, 78, 135, 20);
zhanghao.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.WHITE));
zhanghao.setFont(new Font("宋体",Font.PLAIN,13));
this.add(zhanghao);*/
// zhanghaowb = new JLabel(new ImageIcon("2.png"));
// zhanghaowb.setBounds(90, 73, 194, 31);
// jiantou = new JLabel(new ImageIcon("baijiantou.png"));
// jiantou.setBounds(256, 78, 23, 21);
// jiantou.addMouseListener(this);
// this.add(jiantou);
// this.add(zhanghaowb);
chashamuma.addActionListener(this);
mima = new JPasswordField();
mima.setEchoChar('*');
mima.setFont(new Font("宋体",Font.PLAIN,13));
mima.setBounds(100, 113, 150, 20);
this.add(mima);
zhanghao = new JComboBox();
zhanghao.setEditable(true);
zhanghao.setBounds(100, 78, 150, 20);
zhanghao.setFont(new Font("宋体",Font.PLAIN,13));
this.add(zhanghao);
guanggao = new JLabel(new ImageIcon("guanggao.gif"));
guanggao.setBounds(0, 0, 334, 64);
beijing = new JLabel(new ImageIcon("beijing.jpg"));
beijing.setBounds(0, 64, 334, 154);
wenzi = new JLabel(new ImageIcon("wenzi.jpg"));
wenzi.setBounds(30, 75, 50, 100);
denglu.addActionListener(this);
// zhanghaowb.addMouseListener(this);
// zhanghao.addMouseListener(this);
this.add(wenzi);
this.add(beijing);
this.setLayout(null);
this.add(guanggao);
this.setVisible(true);
this.setDefaultCloseOperation(3);
this.setSize(340, 250);
this.setLocationRelativeTo(null);
}
public static void main(String[] args) {
/*JFrame.setDefaultLookAndFeelDecorated(true);
try {
UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel()) ;
UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
} catch (Exception e) {
System.out.println("Substance Raven Graphite failed to initialize");
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
QQLogin w = new QQLogin();
w.setVisible(true);
}
});*/
new QQLogin();
}
public void mouseClicked(MouseEvent e) {
// TODO 自动生成方法存根
}
public void mouseEntered(MouseEvent e) {
if(e.getSource() == dengluzhuangtai)
{
dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtaidian.jpg"));
}
}
public void mouseExited(MouseEvent e) {
if(e.getSource() == dengluzhuangtai)
{
dengluzhuangtai.setIcon(new ImageIcon("zaixianzhuangtai.jpg"));
}
}
public void mousePressed(MouseEvent e) {
// TODO 自动生成方法存根
}
public void mouseReleased(MouseEvent e) {
// TODO 自动生成方法存根
}
public void mouseDragged(MouseEvent e) {
// TODO 自动生成方法存根
}
public void mouseMoved(MouseEvent e) {
// TODO 自动生成方法存根
}
public class liaotianchuangkou
{
}
class SimThread extends Thread{//线程类
private int current;//进度栏的当前值
private int target;//进度栏的最大值
public SimThread(int t){
current=0;
target=t;
}
public int getTarget(){
return target;
}
public int getCurrent(){
return current;
}
public void run(){//线程体
try{
while (currenttarget !interrupted()){//如果进度栏的当前值小于目标值并且线程没有被中断
sleep(10);
current++;
if(current == 700)
{
sleep(3000);
}
else if(current == 730)
{
sleep(1000);
}
}
}catch (InterruptedException e){}
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == chashamuma)
{
this.setBounds(300, 300, 340, 300);
}
else if(e.getSource() == denglu)
{
String zh = (String) zhanghao.getSelectedItem();
System.out.println(zhanghao.getSelectedItem());
// System.out.println(zhanghao.getItemAt(0));
char [] str = mima.getPassword();
String mima = String.valueOf(str);;
System.out.println(mima);
// Sql login = new Sql();
// if(login.login(zh,mima))
// {
try {
s = new Socket("127.0.0.1",8888);
System.out.println(s);
PrintWriter pw;
Scanner sc;
pw = new PrintWriter(s.getOutputStream(),true);
sc = new Scanner(s.getInputStream());
String str2 = "login#289872400198724#"+zh+"#289872400198724#"+mima;
System.out.println(str2);
pw.println(str2);
String str3 = sc.nextLine();
String yanzheng[] = str3.split("#");
System.out.println(str3);
if(yanzheng[0].equals("true"))
{
System.out.println("登陆成功!");
name = yanzheng[1];
qq = yanzheng[2];
// this.setVisible(false);
// Thread.sleep(5000);
System.out.println("woao"+name);
System.out.println("woai"+qq);
Logined logined = new Logined(name,qq);
this.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(this, "用户名或密码错误!", "用户名或密码错误!", 0);
}
} catch (UnknownHostException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
} catch (IOException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
/*try {
login.rs = login.stat.executeQuery("select * from qquser where username='"+zh+"' and password = '"+mima+"'");
boolean flag = login.rs.next();
if(flag == true)
{
name = login.rs.getString("name");
qq = login.rs.getString("username");
}
else
{
}*/
// } catch (SQLException e1) {
// TODO 自动生成 catch 块
// e1.printStackTrace();
// }
}
else
{
JOptionPane.showMessageDialog(this, "用户名或密码错误", "输入错误", 0);
}
// this.setVisible(false);
//new Logined();
}
}
这种东西,除非是网络上原本就有的。否则你几乎要不到的,即使是简易版想做出来,除非是高手,起码要一个星期。
一.读取Excel文件内容
复制代码代码如下:
/** *//**读取Excel文件的内容
* @param file 待读取的文件
* @return
*/
public static String readExcel(File file)...{
StringBuffer sb = new StringBuffer();
Workbook wb = null;
try ...{
//构造Workbook(工作薄)对象
wb=Workbook.getWorkbook(file);
} catch (BiffException e) ...{
e.printStackTrace();
} catch (IOException e) ...{
e.printStackTrace();
}
if(wb==null)
return null;
//获得了Workbook对象之后,就可以通过它得到Sheet(工作表)对象了
Sheet[] sheet = wb.getSheets();
if(sheet!=nullsheet.length0)...{
//对每个工作表进行循环
for(int i=0;isheet.length;i++)...{
//得到当前工作表的行数
int rowNum = sheet[i].getRows();
for(int j=0;jrowNum;j++)...{
//得到当前行的所有单元格
Cell[] cells = sheet[i].getRow(j);
if(cells!=nullcells.length0)...{
//对每个单元格进行循环
for(int k=0;kcells.length;k++)...{
//读取当前单元格的值
String cellValue = cells[k].getContents();
sb.append(cellValue+" ");
}
}
sb.append(" ");
}
sb.append(" ");
}
}
//最后关闭资源,释放内存
wb.close();
return sb.toString();
}
二.写入Excel文件
这里有很多格式了,比如文本内容加粗,加上某些颜色等,可以参考jxl的api
复制代码代码如下:
/**生成一个Excel文件
* @param fileName 要生成的Excel文件名
*/
public static void writeExcel(String fileName)...{
WritableWorkbook wwb = null;
try ...{
//首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
wwb = Workbook.createWorkbook(new File(fileName));
} catch (IOException e) ...{
e.printStackTrace();
}
if(wwb!=null)...{
//创建一个可写入的工作表
//Workbook的createSheet方法有两个参数,第一个是工作表的名称,第二个是工作表在工作薄中的位置
WritableSheet ws = wwb.createSheet("sheet1", 0);
//下面开始添加单元格
for(int i=0;i10;i++)...{
for(int j=0;j5;j++)...{
//这里需要注意的是,在Excel中,第一个参数表示列,第二个表示行
Label labelC = new Label(j, i, "这是第"+(i+1)+"行,第"+(j+1)+"列");
try ...{
//将生成的单元格添加到工作表中
ws.addCell(labelC);
} catch (RowsExceededException e) ...{
e.printStackTrace();
} catch (WriteException e) ...{
e.printStackTrace();
}
}
}
try ...{
//从内存中写入文件中
wwb.write();
//关闭资源,释放内存
wwb.close();
} catch (IOException e) ...{
e.printStackTrace();
} catch (WriteException e) ...{
e.printStackTrace();
}
}
}
两个类,实现交互不带界面的简单容易让你了解核心的知识
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class MutiChat
{
public static void main(String[] args)
{
MutiChat mc = new MutiChat();
mc.receive().start();
mc.send().start();
}
/**
* 接收信息
*
* @return
*/
private Thread receive()
{
return new Thread()
{
public void run()
{
ServerSocket server_socket = null;
Socket sk = null;
BufferedReader in = null;
try
{
server_socket = new ServerSocket(7777);
sk = server_socket.accept();
in = new BufferedReader(new InputStreamReader(sk
.getInputStream()));
while (true)
{
String str = in.readLine();
System.out.println(str);
}
} catch (Exception e)
{
e.printStackTrace();
}
}
};
}
private Thread send()
{
return new Thread()
{
public void run()
{
Socket client_socket = null;
BufferedReader in = null;
PrintWriter out = null;
while (true)
{
try
{
client_socket = new Socket("127.0.0.1", 8888);
in = new BufferedReader(
new InputStreamReader(System.in));
out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(client_socket
.getOutputStream())), true);
while (true)
{
String str = in.readLine();
out.println(str);
}
} catch (Exception e)
{
try
{
Thread.sleep(1000);
} catch (Exception ex)
{
ex.printStackTrace();
}
}
}
}
};
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class MutiChat2
{
public static void main(String[] args)
{
MutiChat2 mc = new MutiChat2();
mc.receive().start();
mc.send().start();
}
/**
* 接收信息
*
* @return
*/
private Thread receive()
{
return new Thread()
{
public void run()
{
ServerSocket server_socket = null;
Socket sk = null;
BufferedReader in = null;
try
{
server_socket = new ServerSocket(8888);
sk = server_socket.accept();
in = new BufferedReader(new InputStreamReader(sk
.getInputStream()));
while (true)
{
String str = in.readLine();
System.out.println(str);
}
} catch (Exception e)
{
e.printStackTrace();
}
}
};
}
private Thread send()
{
return new Thread()
{
public void run()
{
Socket client_socket = null;
BufferedReader in = null;
PrintWriter out = null;
while (true)
{
try
{
client_socket = new Socket("127.0.0.1", 7777);
in = new BufferedReader(
new InputStreamReader(System.in));
out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(client_socket
.getOutputStream())), true);
while (true)
{
String str = in.readLine();
out.println(str);
}
} catch (Exception e)
{
try
{
Thread.sleep(1000);
} catch (Exception ex)
{
ex.printStackTrace();
}
}
}
}
};
}
}
下面这个是可以带图形界面的
Server:
package ChatIV;
import java.net.*;
import java.io.*;
import java.util.*;
//广播聊天室服务端
public class Server {
public static void main(String args[]){
try {
ServerSocket ss = new ServerSocket(8186);//实现Socket
List sockets = new ArrayList();//创建一个集合,保存文字消息
while(true){
Socket s = ss.accept();//监听8186
sockets.add(s);//向集合中添加Socket的对象S,把听到的内容保存到集合中
Thread t1 = new ChatThread(s,sockets);//线程
t1.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
class ChatThread extends Thread{
Socket s;
List sockets;
public ChatThread(Socket s,List sockets){
this.s=s;
this.sockets=sockets;
}
public void run(){
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(s.getInputStream()));//包装成字符流
while(true){
String str = in.readLine();//读BufferedReader
for(int i=0;isockets.size();i++){//利用For循环遍历集合
Socket s2 = (Socket)sockets.get(i);//创建Socket对象S2,强转成Socket,并获取下标
PrintWriter out = new PrintWriter(s2.getOutputStream());//文本流输出
out.println(str);//打印字符
out.flush();//刷新该流的缓冲
}
}
} catch (IOException e) {}
finally{
try {
s.close();
} catch (IOException e) {}
}
}
}
Client:
package ChatIV;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
//广播聊天室客户端
public class Client {
JTextArea jta;
JTextField jtf;
BufferedReader in;
PrintWriter out;
//Swing画一个界面
private void initGUI(){
JFrame f=new JFrame("Client");
f.setSize(400,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jta=new JTextArea();
jta.setEditable(false);
f.add(new JScrollPane(jta));
jtf=new JTextField();
f.add(jtf,"South");
f.setVisible(true);
jtf.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
String text=jtf.getText();
jtf.setText("");
out.println(text);
out.flush();
}
});
}
//连接初始化
private void initNet(){
try {
Socket s = new Socket("127.0.0.1",8186);//创建Socket端口8186,端口号随意,避免常用端口即可
out = new PrintWriter(s.getOutputStream());//文本流输出,利用Socket对象获得getOutputStream()
in = new BufferedReader(new InputStreamReader(s.getInputStream()));//包装成字符流
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//消息接收
private void receive(){
try {
while(true){
String str = in.readLine();//读BufferedReader
if(str==null){
return ;
}
jta.append("说"+str+"\n");//加载到JTextArea中,显示
}
} catch (IOException e) {
e.printStackTrace();
}
}
private Client(){
this.initGUI();
this.initNet();
}
public static void main(String args[]){
Client c = new Client();
c.receive();
}
}
package ch10;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//定义该类继承自JFrame,实现ActionListener接口
public class LoginTest extends JFrame implements ActionListener
{
//创建JPanel对象
private JPanel jp=new JPanel();
//创建3个标并加入数组
JLabel name = new JLabel("请输入用户名");
JLabel password = new JLabel("请输入密码");
JLabel show = new JLabel("");
private JLabel[] jl={name,password,show};
//创建登陆和重置按扭并加入数组
JButton login = new JButton("登陆");
JButton reset = new JButton("重置");
private JButton[] jb={login,reset};
//创建文本框以及密码框
private JTextField jName=new JTextField();
private JPasswordField jPassword =new JPasswordField();
public LoginTest()
{
//设置布局管理器为空布局,这里自己摆放按钮、标签和文本框
jp.setLayout(null);
for(int i=0;i2;i++)
{
//设置标签和按扭的位置与大小
jl[i].setBounds(30,20+40*i,180,20);
jb[i].setBounds(30+110*i,100,80,20);
//添加标签和按扭到JPanel容器中
jp.add(jl[i]);
jp.add(jb[i]);
//为2个按钮注册动作事件监听器
jb[i].addActionListener(this);
}
//设置文本框的位置和大小,注意满足美观并足够用户名的长度
jName.setBounds(130,15,100,20);
//添加文本框到JPanel容器中
jp.add(jName);
//为文本框注册动作事件监听器
jName.addActionListener(this);
//设置密码框的位置和大小,注意满足美观和足够密码的长度
jPassword.setBounds(130,60,100,20);
//添加密码框到JPanel容器中
jp.add(jPassword);
//设置密码框中的回显字符,这里设置美元符号
jPassword.setEchoChar('$');
//为密码框注册动作事件监听器
jPassword.addActionListener(this);
//设置用于显示登陆状态的标签大小位置,并将其添加进JPanel容器
jl[2].setBounds(10,180,270,20);
jp.add(jl[2]);
//添加JPanel容器到窗体中
this.add(jp);
//设置窗体的标题、位置、大小、可见性及关闭动作
this.setTitle("登陆窗口");
this.setBounds(200,200,270,250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//实现动作监听器接口中的方法actionPerformed
public void actionPerformed(ActionEvent e)
{
//如果事件源为文本框
if(e.getSource()==jName)
{
//切换输入焦点到密码框
jPassword.requestFocus();
}
//如果事件源为重置按扭
else if(e.getSource()==jb[1])
{
//清空姓名文本框、密码框和show标签中的所有信息
jl[2].setText("");
jName.setText("");
jPassword.setText("");
//让输入焦点回到文本框
jName.requestFocus();
}
//如果事件源为登陆按钮,则判断登录名和密码是否正确
else
{
//判断用户名和密码是否匹配
if(jName.getText().equals("lixiangguo")
String.valueOf(jPassword.getPassword()).equals("19801001"))
{
jl[2].setText("登陆成功,欢迎您的到来!");
}
else
{
jl[2].setText("对不起,您的用户名或密码错误!");
}
}
}
public static void main(String[] args)
{
//创建LoginTest窗体对象
new LoginTest();
}
}
这个简单点的