gpt4 book ai didi

java - 在我的新 GUI 中调用我的 run 方法后,如何返回类?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:29 24 4
gpt4 key购买 nike

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);
}
});

}

}

所以我从另一个类(class)调用了 run。我的主要目标是返回到我使用创建的提交按钮调用它的类。有人可以通过提交按钮帮助我返回调用它的类吗?

最佳答案

看看How to Make Dialogs .

模态对话框将在对话框可见时阻止代码执行,并在窗口关闭后返回。然后您就可以从该对象中获取您需要的任何值(它为您提供访问权限)。

或者,您可以使用 Observer Pattern并在需要知道的某些更改时简单地回调类。

关于java - 在我的新 GUI 中调用我的 run 方法后,如何返回类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27031805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com