java 打印显示到服务器,java - 如何将凭据(在登录对话框提示中输入的用户)调用到主服务器并使用Java进行打印? - 堆栈内存溢出...

如何在方法actionPerformed()调用user和pw ,它等于用户在登录对话框提示符中输入到我的main的凭据,以便我可以引用它,或者在那里打印出来?

我尝试设置一些getter和setter但我一直得到一个NullPointerException 。

LoginDialog类:

public class LoginDialog extends JDialog implements ActionListener {

public String user;

public char [] pw;

private String OK = "ok";

private String HELP = "help";

private JFrame controllingFrame; // needed for dialogs

private JTextField userField;

private JPasswordField passwordField;

private TransferService transferService;

BaselineTransferFrame btf;

public LoginDialog(JDialog loginDialog, BaselineTransferFrame bltFrame) {

// Use the default FlowLayout.

controllingFrame = (JFrame) loginDialog.getParent();

transferService = bltFrame.getTransferService();

btf = bltFrame;

// Create everything.

userField = new JTextField(12);

passwordField = new JPasswordField(20);

passwordField.setActionCommand(OK);

passwordField.addActionListener(this);

JLabel uLabel = new JLabel("Enter your Dimensions User ID: ");

JLabel pLabel = new JLabel("Enter password: ");

uLabel.setLabelFor(userField);

pLabel.setLabelFor(passwordField);

// Lay out everything.

JPanel textPane = new JPanel(new GridLayout(3, 1));

textPane.add(uLabel);

textPane.add(userField);

textPane.add(pLabel);

textPane.add(passwordField);

textPane.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder()));

JComponent buttonPane = createButtonPanel(textPane);

add(textPane);

add(buttonPane);

}

protected JComponent createButtonPanel(JPanel p) {

float BTN_SIZE = 16f;

JButton okButton = new JButton("OK");

okButton.setActionCommand(OK);

helpButton.setActionCommand(HELP);

okButton.addActionListener(this);

helpButton.addActionListener(this);

okButton.setFont(okButton.getFont().deriveFont(Font.BOLD, BTN_SIZE));

helpButton.setFont(helpButton.getFont().deriveFont(Font.BOLD, BTN_SIZE));

Boolean enabled = true;

if (enabled) {

okButton.setBackground(new Color(59, 89, 182));

okButton.setEnabled(true);

} else {

okButton.setBackground(new Color(128, 128, 128));

okButton.setEnabled(false);

}

okButton.setForeground(Color.WHITE);

okButton.setFocusPainted(false);

if (enabled) {

helpButton.setBackground(new Color(59, 89, 182));

helpButton.setEnabled(true);

} else {

helpButton.setBackground(new Color(128, 128, 128));

helpButton.setEnabled(false);

}

helpButton.setForeground(Color.WHITE);

helpButton.setFocusPainted(false);

p.add(okButton);

p.add(helpButton);

return p;

}

public void actionPerformed(ActionEvent e) {

String cmd = e.getActionCommand();

if (OK.equals(cmd)) { // Process the password.

user = userField.getText();

pw = passwordField.getPassword();

HashMap connectParms = transferService.getConnectionParms("a");

DimensionsSession dmSession = null;

try {

dmSession = transferService.connectToDimensions(connectParms.get("server"), connectParms.get("connection"), connectParms.get("database"), user, String.valueOf(pw));

System.out.println("Here");

} catch (BaselineTransferException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

if (dmSession != null) {

JOptionPane.showMessageDialog(controllingFrame, "Success! You typed the right password.");

dmSession.close();

controllingFrame.dispose();

} else {

JOptionPane.showMessageDialog(controllingFrame, "Invalid password. Try again.", "Error Message",

JOptionPane.ERROR_MESSAGE);

}

// Zero out the possible password, for security.

Arrays.fill(pw, '0');

passwordField.selectAll();

resetFocus();

} else { // The user has asked for help.

System.exit(0);

JOptionPane.showMessageDialog(controllingFrame,

"You can get the password by searching this example's\n"

+ "source code for the string \"correctPassword\".\n"

+ "Or look at the section How to Use Password Fields in\n"

+ "the components section of The Java Tutorial.");

}

}

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博私信或留言,博看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博删除。 6、可私信博看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博私信或留言,博看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博删除。 6、可私信博看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博私信或留言,博看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博删除。 6、可私信博看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值