2024-05-25 06:48:17 | 我爱编程网
package ibees.qq;
import java.awt.BorderLayout;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
* 仿QQ登录界面,仅供学习参考,涉及到的有窗口居中、JPanel、LayoutManager的使用
* @author hhzxj2008
* */
public class QQLoginView extends JFrame {
/**
*
*/
private static final long serialVersionUID = -5665975170821790753L;
public QQLoginView() {
initComponent();
}
private void initComponent() {
setTitle("用户登录");
//设置LOGO
URL image = QQLoginView.class.getClassLoader().getResource("ibees/qq/images/year.jpg");//图片的位置
JLabel imageLogo = new JLabel(new ImageIcon(image));
add(imageLogo,BorderLayout.NORTH);
//QQ号和密码
JPanel jp = new JPanel();
JPanel jpAccount = new JPanel();
jpAccount.add(new JLabel("帐号"));
JTextField userTextField = new JTextField(15);
jpAccount.add(userTextField);
jpAccount.add(new JLabel("用户注册"));
jp.add(jpAccount);
JPanel jpPass = new JPanel();
jpPass.add(new JLabel("密码"));
JPasswordField passTextField = new JPasswordField(15);
jpPass.add(passTextField);
jpPass.add(new JLabel("找回密码"));我爱编程网
jp.add(jpPass);
//登录设置
JPanel jpstatus = new JPanel();
jpstatus.add(new JLabel("状态"));
JComboBox statusComboBox = new JComboBox();
statusComboBox.addItem("Q我");
statusComboBox.addItem("在线");
statusComboBox.addItem("隐身");
statusComboBox.addItem("离线");
jpstatus.add(statusComboBox);
jpstatus.add(new JCheckBox("记住密码"));
jpstatus.add(new JCheckBox("自动登录"));
jp.add(jpstatus);
add(jp);
//底部登录按钮
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BorderLayout());
bottomPanel.add(new JButton("设置"),BorderLayout.WEST);
bottomPanel.add(new JButton("登录"),BorderLayout.EAST);
add(bottomPanel,BorderLayout.SOUTH);
setSize(324,230);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
}
/**
* @param args
*/
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable(){
@Override
public void run() {
new QQLoginView().setVisible(true);
}
});
}
}
两种解决办法,
第一种使用纯java的方式,使用组件JTextPane 或者JEditorPane 来显示图片和文字
第二种使用JEditorPane,但是里面存放HTML代码. 用HTML来控制文字和图片的显示
我爱编程网(https://www.52biancheng.com)小编还为大家带来用Java编写类似QQ对话框程序的相关内容。
给你个Socket/ServerSocket写的小例子,看看能不能帮到你哦:
先运行ServerGUI,启动服务器端,再运行ClientGUI,双方就可以发送字符串了...
ServerGUI类:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
@SuppressWarnings("serial")
public class ServerGUI extends JFrame {
private JTextArea jta, jtaInput;
private JPanel jtaAreaPane;
private JPanel j;
private JButton buttonSubmit, buttonExit;
private String stringGet = null;
private OurServer os = null;
public ServerGUI(String s) {
super(s);
jtaAreaPane = new JPanel();
jtaAreaPane.setLayout(new GridLayout(2, 1));
jta = new JTextArea(7, 35);
jta.setLineWrap(true);
jta.setBackground(new Color(169, 255, 128));
JScrollPane jsp = new JScrollPane(jta);
jtaInput = new JTextArea(7, 35);
jtaInput.setLineWrap(true);
jtaInput.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 10) {
String s = jtaInput.getText();
jtaInput.setText(null); // 输入框重新设为空
jta.append("\n" + "你发送了:" + s.trim());
stringGet = s;
if (stringGet != null) {
System.out.println("stringGet:" + stringGet);
try {
os.getOsw().write(stringGet + "\n");
os.getOsw().flush();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
});
jtaInput.setBackground(new Color(133, 168, 250));
JScrollPane jspIn = new JScrollPane(jtaInput);
jtaAreaPane.add(jsp);
jtaAreaPane.add(jspIn);
j = new JPanel();
buttonSubmit = new JButton("提交");
buttonSubmit.addActionListener(new SetButtonSubmit());
buttonExit = new JButton("关闭");
buttonExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
j.add(buttonSubmit);
j.add(buttonExit);
setLayout(new BorderLayout());
add(jtaAreaPane, BorderLayout.CENTER);
add(j, BorderLayout.SOUTH);
setSize(new Dimension(400, 500));
setLocation(500, 300);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
new Thread(new ServerOurRead()).start();
os = new OurServer();
}
public String GetString() {
return stringGet;
}
public void setStringGet(String s) {
this.stringGet = s;
}
class SetButtonSubmit implements ActionListener {
@SuppressWarnings("static-access")
public void actionPerformed(ActionEvent e) {
String s = jtaInput.getText();
jtaInput.setText(null);
jta.append("\n" + "你发送了:" + s.trim());// jta.setText("你发送了:"+oc.s);
stringGet = s;
if (stringGet != null) {
System.out.println("stringGet:" + stringGet);
try {
os.getOsw().write(stringGet + "\n");
os.getOsw().flush();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
// 接收来自客户端的线程
class ServerOurRead implements Runnable {
public void run() {
while (true) {
try {
jta.append("\n来自客户端:" + os.getBr().readLine());
} catch (Exception e1) {
e1.printStackTrace();
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void main(String args[]) {
new ServerGUI("服务器对话框");
}
}
OurServer类:
import java.util.*;
import java.io.*;
import java.net.*;
public class OurServer {
private ServerSocket serverSocket = null;
private OutputStream os = null;
private InputStream is = null;
private OutputStreamWriter osw = null;
private InputStreamReader isr = null;
private BufferedReader br = null;
private ArrayList
private Scanner console = new Scanner(System.in);
public OurServer() {
try {
serverSocket = new ServerSocket(22222);
System.out.println("serverSocket is waiting...");
Socket soc = serverSocket.accept();
os = soc.getOutputStream();
is = soc.getInputStream();
osw = new OutputStreamWriter(os);
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
} catch (IOException e) {
e.printStackTrace();
}
}
// 从客户端读信息的线程
public static void main(String args[]) {
}
public BufferedReader getBr() {
return br;
}
public void setBr(BufferedReader br) {
this.br = br;
}
public OutputStreamWriter getOsw() {
return osw;
}
public void setOsw(OutputStreamWriter osw) {
this.osw = osw;
}
}
ClientGUI类:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
@SuppressWarnings("serial")
public class ClientGUI extends JFrame {
private JTextArea jta, jtaInput;
private JPanel jtaAreaPanel;
private JPanel j;
private JButton buttonSubmit, buttonExit;
private String stringGet = null;
private OurClient oc = null;
public ClientGUI(String s) {
super(s);
jtaAreaPanel = new JPanel();
jtaAreaPanel.setLayout(new GridLayout(2, 1));
jta = new JTextArea(7, 35);
jta.setLineWrap(true);
jta.setBackground(new Color(169, 255, 128));
JScrollPane jsp = new JScrollPane(jta);
jtaInput = new JTextArea(7, 35);
jtaInput.setLineWrap(true);
jtaInput.setBackground(new Color(133, 168, 250));
jtaInput.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == 10) {
String s = jtaInput.getText();
jtaInput.setText(null); // 输入框重新设为空
jta.append("\n" + "你发送了:" + s.trim());
stringGet = s;
if (stringGet != null) {
System.out.println("stringGet:" + stringGet);
try {
oc.getOsw().write(stringGet + "\n");
oc.getOsw().flush();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
});
JScrollPane jspIn = new JScrollPane(jtaInput);
jtaAreaPanel.add(jsp);
jtaAreaPanel.add(jspIn);
j = new JPanel();
buttonSubmit = new JButton("提交");
buttonSubmit.addActionListener(new SetButtonSubmit());
buttonExit = new JButton("关闭");
buttonExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
j.add(buttonSubmit);
j.add(buttonExit);
setLayout(new BorderLayout());
add(jtaAreaPanel, BorderLayout.CENTER);
add(j, BorderLayout.SOUTH);
setSize(new Dimension(400, 500));
setLocation(500, 300);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
// 启动读取服务端信息线程
new Thread(new ServerOurRead()).start();
oc = new OurClient();
}
public String GetString() {
return stringGet;
}
public void setStringGet(String s) {
this.stringGet = s;
}
class SetButtonSubmit implements ActionListener {
@SuppressWarnings("static-access")
public void actionPerformed(ActionEvent e) {
String s = jtaInput.getText();
jtaInput.setText(null); // 输入框重新设为空
jta.append("\n" + "你发送了:" + s.trim());
stringGet = s;
if (stringGet != null) {
System.out.println("stringGet:" + stringGet);
try {
oc.getOsw().write(stringGet + "\n");
oc.getOsw().flush();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
// 接收来自客户端的线程
class ServerOurRead implements Runnable {
public void run() {
while (true) {
try {
// oc.getBr().readLine()此方法一直在读,直到流中有数据
jta.append("\n来自客户端:" + oc.getBr().readLine());// readLine()
} catch (Exception e1) {
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void main(String args[]) {
new ClientGUI("对话框");
}
}
OurClient 类:
import java.io.*;
import java.net.*;
import java.util.*;
public class OurClient {
private Socket socket = null;
private OutputStream os = null;
private InputStream is = null;
private OutputStreamWriter osw = null;
private InputStreamReader isr = null;
private BufferedReader br = null;
private Scanner console = null;
private static String s = null;
private static String In = null;
public OurClient() {
console = new Scanner(System.in);
try {
socket = new Socket("127.0.0.1", 22222);
os = socket.getOutputStream();
is = socket.getInputStream();
osw = new OutputStreamWriter(os);
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// 从服务端读信息的线程
public BufferedReader getBr() {
return br;
}
public void setBr(BufferedReader br) {
this.br = br;
}
public OutputStreamWriter getOsw() {
return osw;
}
public void setOsw(OutputStreamWriter osw) {
this.osw = osw;
}
public static void main(String args[]) {
}
}
mysql,php中多对多关系的问题用一条sql语句就行设表结构如下:编辑员表 editor: id, name,pwd,newsblocks新闻版块表 news : id, namesql语句如下:SELECT editor.*,GROUP_CONCAT(news.`name`) AS newsblock_name FROM editorLEFT
php如何生成加粗或者斜体的文字样式图片加粗或者斜体的文字可以用php的函数控制.我想你是想生成验证码图片是吗?如果是想生成验证么图片有几个函数可以考虑imagecreate($length,$height)创建图片.参数是图片的宽度和高度imagecolorallocate($image,$r,$g,$b)设置背景色,rbg就是图片的三色rgb参数.这个可以由传
一个java程序为什么不能显示图片?编译出错的原因是因为JPanel是没有setIcon()这个方法!你可以试试用JLabel代替JPanel看看行不行,但这样只是可以用setIcon(),若只就你贴出的代码看,是可以用JLabel,但能否正确编译及运行还要视乎其他代码!java程序在linux下无法显示图片1.调用"images"文件夹里的文件放在ImageIcon里显示
PHP如何获取图片的哈希值啊。。你好,哈希算法很多,自带有,sha1函数跟md5函数,获取图片的哈希值要读取内容去运算,如$file=file_get_contents("图片路径");echosha1($file);//哈希值,echomd5($file);//md5值,这两个都是摘要。谢谢php修改文档属性摘要的标题怎么设置php修改文档属性摘要的标题设置方法:1、
如何用Python编写一个聊天室python聊天室(python2.7版本):暂时先给出两种版本的,tcp+udp都是分别运行server.py和client.py,就可以进行通讯了。别外还有websocket版本,这个是有web界面的和基本web服务的,如果需要的话,我会把基本的代码贴一版上来。TCP版本:socket-tcp-server.py(服务端):#
使用Java做一个走马灯,源代码?import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.HeadlessException;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event
glob语法PHP的glob函数是一个用于在文件系统中执行模式匹配的实用工具,其原型如下:glob(constchar*pattern,intflags,interrfunc(constchar*epath,inteerrno),glob_t*pglob);这个函数的核心参数是pattern,它是一个必需的字符串,用于定义检索模式。例如,你可以用它来查找以'.txt'结尾的
用PHP实现分页显示要求实现和图片一样的功能希望你能用得上!<?phpfunctionpage($page,$total,$phpfile,$pagesize=10,$pagelen=7){$pagecode=’’;//定义变量,存放分页生成的HTML$page=intval($page);//避免非数字页码$total=intval($total);//保证总记
2025-02-01 20:24:39
2024-01-05 14:11:24
2025-02-12 03:21:37
2025-02-10 15:19:48
2025-01-28 17:58:32
2024-11-22 05:08:01