java 变量 跨类_访问JAVA中的另一个类变量

我的应用程序下面有Loginscreen; (我使用netbeans gui设计师)

public class loginscreen extends javax.swing.JFrame {

/**

* Creates new form loginscreen

*/

public loginscreen() {

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")

//

private void initComponents() {

Uname_Textfield = new javax.swing.JTextField();

Password_PasswordField = new javax.swing.JPasswordField();

Bağlan_Buton = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setResizable(false);

Uname_Textfield.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Uname_TextfieldActionPerformed(evt);

}

});

Bağlan_Buton.setText("Bağlan");

Bağlan_Buton.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

Bağlan_ButonActionPerformed(evt);

}

});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(10, 10, 10)

.addComponent(Uname_Textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup()

.addGap(10, 10, 10)

.addComponent(Password_PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup()

.addGap(54, 54, 54)

.addComponent(Bağlan_Buton)))

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(11, 11, 11)

.addComponent(Uname_Textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addComponent(Password_PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(Bağlan_Buton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

pack();

setLocationRelativeTo(null);

}//

private void Uname_TextfieldActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

}

private void Bağlan_ButonActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String user=Uname_Textfield.getText();

String pwd= new String (Password_PasswordField.getPassword());

try {

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

String connectionUrl = "jdbc:sqlserver://192.168.131.10;" + "databaseName=ExampleDB;" + "user=" + user + ";" + "password=" + pwd + ";";

Connection con = DriverManager.getConnection(connectionUrl);

new ProgramPenceresi().setVisible(true);

dispose();

}

catch (SQLException e) {

JOptionPane.showMessageDialog(this, "Kullanıcı Adı veya Şifre Yanlış!");

}

catch (ClassNotFoundException cE) {

System.out.println("Class Not Found Exception: "+ cE.toString());

}

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

/* Set the Nimbus look and feel */

//

/* 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(loginscreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(loginscreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(loginscreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(loginscreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

}

//

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new loginscreen().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton Bağlan_Buton;

private javax.swing.JPasswordField Password_PasswordField;

private javax.swing.JTextField Uname_Textfield;

// End of variables declaration

}

我使用此loginscreen来识别数据库中的用户 . 我有另一个SQLSP类用于执行DB中的存储过程 .

如果用户使用真实登录详细信息成功登录系统,则屏幕上会显示另一个java框架 . 当用户与此屏幕交互并从SQLSP类调用某些sqlsp时,我必须使用loginscreen.java中的uname&password登录到db

但uname和密码存储在

privatevoidBağlan_ButonActionPerformed(java.awt.event.ActionEvent evt)

公共类loginscreen扩展了javax.swing.JFrame

如何从另一个类访问用户和pwd变量?

我试试

loginscreen logindetails = new loginscreen();

String username = logindetails.user;

但没有帮助 . 我怎样才能访问它们?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值