3个回答
展开全部
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
import java.awt.color.*;
import java.util.Vector;
public class Login extends JFrame
implements ActionListener
{
int port=3000;
static Vector v=new Vector();
private JLabel qqid;
private JLabel qqpwd;
private JTextField use;
private JPasswordField pwd;
private JButton login;
private JButton reg;
private JButton canel;
private JLabel imageLabel;
private Icon image;
JPanel pane;
public Login(String str){
super(str);
int screenWidth = (int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = (int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
image=new ImageIcon("picture\\科比.png");
imageLabel=new JLabel(image);
imageLabel.setBounds(0,0,230,75);
this.add(imageLabel);
qqid=new JLabel("QQ号码:");
qqpwd=new JLabel("QQ密码:");
use=new JTextField();
pwd=new JPasswordField('*');
login=new JButton("登录");
reg=new JButton("注册");
canel=new JButton(" 取消");
pane=new JPanel();
pane.setLayout(null);
pane.add(qqid);
pane.add(use);
pane.add(qqpwd);
pane.add(pwd);
pane.add(canel);
pane.add(login);
pane.add(reg);
qqid.setBounds(15,80,150,20);
use.setBounds(65,80,150,20);
qqpwd.setBounds(15,115,150,20);
pwd.setBounds(65,115,150,20);
login.setBounds(10,160,60,20);
canel.setBounds(80,160,65,20);
reg.setBounds(160,160,60,20);
this.getContentPane().add(pane).setBackground(Color.white);
this.getContentPane().add(pane);
login.addActionListener(this);
reg.addActionListener(this);
canel.addActionListener(this);
this.setResizable(false);
this.setSize(245,240);
this.setLocation((screenWidth-245)/2, (screenHeight-240)/2);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
JButton jb=(JButton)e.getSource();
if(jb==login) {
Talk talk=new Talk();
DatagramPacket dp=null;
try{
talk.sendMSG("登录"+":"+use.getText().trim()+":"+pwd.getText().trim()+":"+port,"127.0.0.1",3001);
dp=talk.getMsg(port);
}
catch(Exception ex) {
}
String re=new String(dp.getData(),0,dp.getData().length);
if(re.trim().equals("success"))
{
this.setVisible(false);
new Chat(use.getText().trim(),"127.0.0.1","port");
}
else
JOptionPane.showMessageDialog(pane,"登录失败 请重新登录","错误",JOptionPane.INFORMATION_MESSAGE);
}else if(jb==canel){
this.setVisible(false);
}
else if(jb==reg){
new Reg();
}
}
public static void main(String args[]){
new Login("J_QQ用户登录界面");
}}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
import java.awt.color.*;
import java.util.Vector;
public class Login extends JFrame
implements ActionListener
{
int port=3000;
static Vector v=new Vector();
private JLabel qqid;
private JLabel qqpwd;
private JTextField use;
private JPasswordField pwd;
private JButton login;
private JButton reg;
private JButton canel;
private JLabel imageLabel;
private Icon image;
JPanel pane;
public Login(String str){
super(str);
int screenWidth = (int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = (int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
image=new ImageIcon("picture\\科比.png");
imageLabel=new JLabel(image);
imageLabel.setBounds(0,0,230,75);
this.add(imageLabel);
qqid=new JLabel("QQ号码:");
qqpwd=new JLabel("QQ密码:");
use=new JTextField();
pwd=new JPasswordField('*');
login=new JButton("登录");
reg=new JButton("注册");
canel=new JButton(" 取消");
pane=new JPanel();
pane.setLayout(null);
pane.add(qqid);
pane.add(use);
pane.add(qqpwd);
pane.add(pwd);
pane.add(canel);
pane.add(login);
pane.add(reg);
qqid.setBounds(15,80,150,20);
use.setBounds(65,80,150,20);
qqpwd.setBounds(15,115,150,20);
pwd.setBounds(65,115,150,20);
login.setBounds(10,160,60,20);
canel.setBounds(80,160,65,20);
reg.setBounds(160,160,60,20);
this.getContentPane().add(pane).setBackground(Color.white);
this.getContentPane().add(pane);
login.addActionListener(this);
reg.addActionListener(this);
canel.addActionListener(this);
this.setResizable(false);
this.setSize(245,240);
this.setLocation((screenWidth-245)/2, (screenHeight-240)/2);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
JButton jb=(JButton)e.getSource();
if(jb==login) {
Talk talk=new Talk();
DatagramPacket dp=null;
try{
talk.sendMSG("登录"+":"+use.getText().trim()+":"+pwd.getText().trim()+":"+port,"127.0.0.1",3001);
dp=talk.getMsg(port);
}
catch(Exception ex) {
}
String re=new String(dp.getData(),0,dp.getData().length);
if(re.trim().equals("success"))
{
this.setVisible(false);
new Chat(use.getText().trim(),"127.0.0.1","port");
}
else
JOptionPane.showMessageDialog(pane,"登录失败 请重新登录","错误",JOptionPane.INFORMATION_MESSAGE);
}else if(jb==canel){
this.setVisible(false);
}
else if(jb==reg){
new Reg();
}
}
public static void main(String args[]){
new Login("J_QQ用户登录界面");
}}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Jframe.setAlwaysOnTop(boolean b)可以设置是否前端显示。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询