[英]How do I return to the class after I've called my run method in my new GUI?
public LogInDatabase() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
picture = new javax.swing.JLabel();
userNameTextField = new javax.swing.JTextField();
labelUserName = new javax.swing.JLabel();
labelPassword = new javax.swing.JLabel();
passwordTextView = new javax.swing.JTextField();
submitButton = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
Names = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
picture.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Learn/Image/newpackage/colors.jpg"))); // NOI18N
labelUserName.setFont(new java.awt.Font("Georgia", 0, 18)); // NOI18N
labelUserName.setText("User Name");
labelUserName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
labelPassword.setFont(new java.awt.Font("Georgia", 0, 18)); // NOI18N
labelPassword.setText("Password");
labelPassword.setBorder(javax.swing.BorderFactory.createEtchedBorder());
submitButton.setBackground(new java.awt.Color(255, 51, 51));
submitButton.setLabel("Submit");
submitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
submitButtonActionPerformed(evt);
}
});
jButton1.setText("Print");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
Names.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
Names.setText("Team 1 Database - Dean Bailey, Josh Dixie, Ben Boudra, Trevor, Abel Amadou, Jalen");
Names.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
jLabel2.setText("Status");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(394, 394, 394)
.addComponent(submitButton)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(passwordTextView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(labelPassword))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addGap(260, 260, 260)
.addComponent(userNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(labelUserName)))
.addGap(325, 325, 325))
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(picture, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(45, 45, 45)
.addComponent(Names, javax.swing.GroupLayout.PREFERRED_SIZE, 776, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(407, 407, 407)
.addComponent(jLabel2)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {labelPassword, labelUserName, passwordTextView, userNameTextField});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(Names, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(picture, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelUserName)
.addComponent(userNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelPassword)
.addComponent(passwordTextView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(submitButton)
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {labelPassword, labelUserName, passwordTextView, userNameTextField});
pack();
}// </editor-fold>
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
//If something returns a number then its inval
userName = userNameTextField.getText();
password = passwordTextView.getText();
//call = new GetThePwUserTest(userName, password);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.out.println(getPassword());
System.out.println(getUserName());
userPwHolder[0] = userName;
userPwHolder[1] = password;
}
public String getUserName(){
return userName;
}
public String getPassword(){
return password;
}
/**
* @param args the command line arguments
*/
/* public static void main(String args[]) {
// Set the Nimbus look and feel
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
// If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
// For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
// Create and display the form
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LogInDatabase().setVisible(true);
}
});
}*/
public void run(){
// Set the Nimbus look and feel
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
// If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(LogInDatabase.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
// Create and display the form
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LogInDatabase().setVisible(true);
}
});
}
}
So I called run from another class. 所以我打电话给另一个班。 My main goal is to return to the class I called it from with the submit button that I have created.
我的主要目标是返回我使用我创建的提交按钮调用它的类。 Can someone help me return to the class thats called it through the submit button?
有人可以帮我回到通过提交按钮调用它的类吗?
Take a look at How to Make Dialogs . 看看如何制作对话框 。
A modal dialog will block at the code execution at the point the dialog is made visible and will return once the window has dismissed. 模式对话框将阻止代码执行时对话框可见,并在窗口解除后返回。 You would then be in a position to get what ever values you needed from the object (that it proivde access for you to get).
然后,您就可以从对象中获得所需的值(它可以为您提供访问权限)。
Alternatively, you could use an Observer Pattern and simply call the class back when something has changed that it would need to know about. 或者,您可以使用观察者模式 ,只需在需要了解的内容发生变化时调用该类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.