我創建了兩個swing.JFrame
s。 登錄GUI和用戶GUI。我要的是當它切換到登錄GUI用戶圖形界面,存在一種需要改變爲("you're logged in as" + username);
在swing中聲明的運行方法.Jframe類
我user
JFrame的源代碼嘗試這種代碼的用戶界面一Jlabel
。
`loggedInAsLable.setText("you're logged in as" + username);`
的方法
,這就是所謂的用戶jframe
主要方法。但由於某些原因 它不起作用。
當Jframe變得可見時,我該如何運行一些方法?
public class CustomerServiceOfficerUI extends javax.swing.JFrame {
private static Statement st;
ResultSet rs;
Connection con = null;
Login loginUI = new Login(); // gets current user Id
Employee cso = new CustomerServiceOfficer(); //creates new customer service officer object
/**
* Creates new form CustomerServiceOfficer
*/
public CustomerServiceOfficerUI() {
initComponents();
}
public void getCSOdetails() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/flyingcarsdb", "root", "");
System.out.println("database connected");
} catch (ClassNotFoundException | SQLException ex) {
System.out.println("Error: " + ex);
}
try {
// Retrieve customer service officer details
st = con.createStatement();
String query = "select * FROM customerserviceofficer WHERE Id = '" + loginUI.getCurrentUserId() + "'";
rs = st.executeQuery(query);
while (rs.next()) {
//Assign the details with setters
cso.setFname(rs.getString("Fname"));
cso.setEmail(rs.getString("Email"));
}
} catch (Exception ex) {
System.out.println("Error : " + ex);
}
loggedInAsLable.setText("you're logged in as : " + cso.getId());
//this is where LABLE is changed, 'cso.getId()' returns the user ID
}
顯示您的代碼,在其中更改標籤 –
首先,請勿爲此使用框架,請在您的登錄視圖中使用對話框。當用戶通過身份驗證並關閉對話框時,它應該返回調用者的會話信息。這是[Model-View-Controller]的基礎(http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) – MadProgrammer
我已經添加了代碼。標籤在一種方法中被破壞。 'getCSOdetails()',並在'CustomerServiceOfficerUI'類的主方法中調用該方法 –