Package com.practice;
Import Java.awt.Toolkit;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.util.ArrayList;
Import java.util.List;
Import Javax.swing.ImageIcon;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
Import Javax.swing.JOptionPane;
Import Javax.swing.JPanel;
Import Com.exercise.dbo.DBManage;
/**
*
* Function: Event answer operation
* @author Dreamer
*date April 28, 2016 12:00:19
*
*/
public class MainFrame extends jframe{
Private String Currentid=null;
Private jlabel[] Lblfriends =null;
Private JLabel lblQQId1 = new JLabel ("QQ number:");
Public MainFrame (String CurrentID) {
if (currentid==null) {
This.currentid= "10000";
}else{
This.currentid=currentid;
}
Default Close Form
This.setdefaultcloseoperation (Jframe.exit_on_close);
Set Title
This.settitle ("QQ login");
Set size
This.setsize (300, 600);
Set Form Center
Setcenterlocation ();
Show form
This.setvisible (TRUE);
Set the form user name
Setcurrtilt ();
Show Friend info
Setfriends ();
}
private void Setcurrtilt () {
String SQL =string.format ("select * from Users where id=%s", This.currentid);
ResultSet rs = dbmanage.myexecutequery (SQL);
try {
if (Rs.next ()) {
This.settitle (Rs.getint ("id") + ":" +rs.getstring ("nickname");
}
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}finally{
Turn off data connections
Dbmanage.closeconnection ();
}
}
private void Setfriends () {
JPanel ContentPane = (JPanel) getcontentpane ();
Contentpane.setlayout (NULL);
Contentpane.setlayout (NULL);
String SQL =string.format
("SELECT * from the Users where ID in (select friendID from friends where hostid=%s);"
, This.currentid);
ResultSet rs= dbmanage.myexecutequery (SQL);
try {
List <String> friendlist = new arraylist<string> ();
while (Rs.next ()) {
int id = rs.getint ("id");
String nickname = rs.getstring ("nickname");
String Strfaceid =rs.getstring ("FaceId");
Determines whether the empty
if (Strfaceid.isempty ()) {
Strfaceid= "1";
}
StringBuffer sb=new StringBuffer ();
Sb.append (ID);
Sb.append (",");
Sb.append (nickname);
Sb.append (",");
Sb.append (Strfaceid);
Add to Data collection
Friendlist.add (Sb.tostring ());
}
Specify the length for the collection
Lblfriends=new jlabel[friendlist.size ()];
for (int i=0;i<lblfriends.length;i++) {
Lblfriends[i]=new JLabel (Friendlist.get (i));
if (i==0) {
Lblfriends[i].setbounds (30,40,150,100);
}else{
Lblfriends[i].setbounds (30,lblfriends[i-1].gety () +40,150,100);
}
String faceId = Friendlist.get (i). Split (",") [2];
Picture path
String Imgurl = String.Format ("images/%s.jpg", faceId);
Lblfriends[i].seticon (New ImageIcon (Imgurl));
Lblfriends[i].seticontextgap (Jlabel.bottom);
Contentpane.add (Lblfriends[i]);
}
Lblqqid1.seticon (New ImageIcon ("images/1-1.jpg"));
Lblqqid1.seticontextgap (Jlabel.bottom);
Lblqqid1.setbounds (10, 5, 80, 50);
Contentpane.add (LBLQQID1);
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}finally{
Turn off data connections
Dbmanage.closeconnection ();
}
}
/**
* Set Form Center
*/
private void Setcenterlocation () {
This.setlocation (
(int) Toolkit.getdefaulttoolkit (). Getscreensize (). GetWidth ()-this.getwidth ())/2,
((int) Toolkit.getdefaulttoolkit (). Getscreensize (). GetHeight ()-this.getheight ())/2
);
}
}
Java interface is very difficult to control ah, write and write don't know how to continue ...