首先,请放心,我现在已经阅读了每篇 Oracle Java 文章和教程大约 6 次,所以如果你能提供帮助,你必须做得比提供 Oracle 页面的链接更好。对不起,如果这听起来很粗鲁。
显然我不知道字符串是如何工作的。我试图让 4 个 jButtons 在按下时将它们的值发送到一个字符串,这样只有最后一个按下的按钮才会在字符串或值中记录它的(名称、文本、任何工作),以便我可以连接它jLabel 消息的值。
所以这里有两个问题,我不能正确设置“状态”按钮,然后我需要能够取值并将其放入 jLabel 中。
您可以通过查看此屏幕截图来了解我卡在哪里:http: //krisbunda.com/gui2.png
查看它在哪里显示“null”而不是 4 个“状态”按钮中的 1 个(“已发货”或“已加载”等)
private void shippedButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(loadedButton.getText());
}
private void loadedButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(loadedButton.getText());
}
private void outReadyButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(outsideReadyButton.getText());
}
private void outNotReadyButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(outsideNotReadyButton.getText());
}
private void enterButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Confirmation.setVisible(true);
Confirmation.setBounds(300,200,900,400);
Confirmation.setModal(rootPaneCheckingEnabled);
confirmationLabel.setText("You are about to send this message:"
+ "\n #" + display.getText()+ " is currently " + status);
}
private void confirmationNoButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Confirmation.dispose();
}
任何帮助是极大的赞赏。
编辑:
感谢您的帮助,这是我为“新行”问题找到的解决方法:我使用了 2 个 JLabels。
并像这样编码:
private void enterButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Confirmation.setVisible(true);
Confirmation.setBounds(200,300,1000,400);
Confirmation.setModal(rootPaneCheckingEnabled);
confirmationLabel1.setText("You are about to send this message:");
confirmationLabel2.setText("PS# " + display.getText()+ " is currently " + status);
}
这是一段代码来说明“充满鳗鱼的气垫船”所回答的修复:
1.) 添加非局部变量/字符串:
public class PlanterStatusUI extends javax.swing.JFrame
{
/** Creates new form PlanterStatusUI */
public PlanterStatusUI() {
initComponents();
}
public String status = new String(); {
}
2.) 更改按钮代码:
private void shippedButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
status = shippedButton.getText();
}