Input information, click on the list to update the input box,
Clearly method was introduced into the value, print and output, but the setText () is not running
This is successful entry data, generated on the right side of the list
When click on the right side of the list on the left side of the box is not refresh
The judge to determine the empty setText () so that
//click ok button
If (um participant etSource ()==button7) {
If (flagAge & amp; & FlagClass & amp; & FlagID & amp; & FlagName & amp; & FlagSex) {
The sta. ExecuteUpdate (into);
JOptionPane. ShowMessageDialog (null, "added success!" );
//to empty input box
StuName. SetText (" ");
StuAge. SetText (" ");
StuClass. SetText (" ");
StuID. SetText (" ");
StuSex. SetText (" ");
//text field display order
Tamlh. SetText (" ");//to empty
Tamlh. Append (beginTime + "execution success:" + into + "\ n");
//add into the collection box list item
StuList. The add (+ nameText IDText + ", ");
} else {
Sta. ExecuteUpdate (update);//delete empty value
JOptionPane. ShowMessageDialog (null, "you enter illegal!" );
Tamlh. SetText (" ");//to empty
Tamlh. Append (beginTime + ": please enter the complete information about students. \n");
}
}
Post the source code below the registered listener stuList. AddActionListener (new ListListener ());//call the class: list item click method of the list click
See what baidu said thread problem, but I write a thread setText () don't run!
String nameList=null;
String stuClassList=null;
String IDList=null;
String sexList=null;
String ageList=null;
//constructor transfer List query in the List of values assigned to input box
Public void stuText (String nameList, String stuClassList, String IDList, String sexList, String ageList) {
Newf Listrun=new newf ();
This. NameList=nameList;
Enclosing stuClassList=stuClassList;
Enclosing IDList=IDList;
Enclosing sexList=sexList;
Enclosing ageList=ageList;
Thread th=new Thread (Listrun);
Th. The start ();
System. The out. Println (" run "+ + + IDList stuClassList nameList + sexList + ageList);
}
@ Override
Public void the run () {
StuName. SetText (nameList);
StuAge. SetText (stuClassList);
StuClass. SetText (IDList);
StuID. SetText (sexList);
StuSex. SetText (ageList);
System. The out. Println (" run 111111 "+ + + IDList stuClassList nameList + sexList + ageList);
}
This calls when class
Package DaZuoYe;
Import the Java. The awt. Event. An ActionEvent;
Import the Java. The awt. Event. ActionListener;
Import the Java. The awt. Event. ItemEvent;
Import the Java. The awt. Event. ItemListener;
Import the Java. SQL. *;
import java.util.Arrays;
The class ListListener implements ActionListener, ItemListener {
String nameList=null;
String stuClassList=null;
String IDList=null;
String sexList=null;
String ageList=null;
@ Override
Public void itemStateChanged (ItemEvent e) {
//TODO Auto - generated method stub
//System. Out. Println (um participant etSource ());
}
@ Override
Public void actionPerformed (an ActionEvent e) {
//TODO Auto - generated method stub
//System. Out. Println (um participant etActionCommand ());
String STR=um participant etActionCommand ();
String [] arr=STR. The split (", ");//to use, split
System.out.println(Arrays.toString(arr));
Try {
Class.forName("com.mysql.cj.jdbc.Driver");//load driver
Connection conn=DriverManager. GetConnection (//link database
"JDBC: mysql://112.125.95.197:3306/Java",
"Java" and "Aa316216");//set up the database connection
The Statement sta=conn. CreateStatement ();//the sta executing SQL statements
String select="select * from stu where name='" + arr [1] +
"' and ID='" + arr [0] +"' ";
System. Out. Println (arr arr [0] + [1]).
The ResultSet rs=sta. ExecuteQuery (select);
While (rs), next ()) {
NameList=rs. Get string (1);
StuClassList=rs. Get string (2);
IDList=rs. Get string (3);
SexList=rs. Get string (4);
AgeList=rs. Get string (5);
}
System. Out. Println (nameList + stuClassList + IDList + + ageList sexList);
New newf (). StuText (nameList, stuClassList, IDList sexList, ageList);
{} to catch (a ClassNotFoundException ClassNotFoundException)
ClassNotFoundException. PrintStackTrace ();
{} the catch (SQLException throwables)
Throwables. PrintStackTrace ();
}
}
}
I'm afraid that I said the novice do not understand,
Wanted to stick all the code out and found that not enough words ,
For bosses to reassure!