我正在使用两个JFrame,POS和金额。当我单击POS框架上的“值”按钮时,它将调用“金额”类供我在其中输入value(#),而当我单击ENTER时,这些值应被转回到POS框架中的文本区域。通过创建POS jframe的新对象,我可以使文本出现在文本区域中,我要做的是将值放回到已经打开的原始POS框架中。
请参见下面的代码...
public class Amounts extends javax.swing.JFrame {
String val;
public Amounts(){
initComponents();
}
public Amounts(String AmtVal) {
this.val = AmtVal;
String getValue = txtField.getText();
txtField.setText(val + getValue);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String Enternum = txtField.getText();
if (Enternum == "")
{
txtField.setText(jButton1.getText());
}
else {
Enternum = txtField.getText() + jButton1.getText();
txtField.setText(Enternum);
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String Enternum = txtField.getText();
if (Enternum == "")
{
txtField.setText(jButton2.getText());
}
else {
Enternum = txtField.getText() + jButton2.getText();
txtField.setText(Enternum);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String Enternum = txtField.getText();
if (Enternum == "")
{
txtField.setText(jButton3.getText());
}
else {
Enternum = txtField.getText() + jButton3.getText();
txtField.setText(Enternum);
}
}
private void jEnterActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String data = txtField.getText();
new POS_System(data).setVisible(true);
}
// Variables declaration - do not modify
private javax.swing.JButton jEnter;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
}
POS类代码:
public class POS_System extends javax.swing.JFrame {
public POS_System() {
initComponents();
}
String val ="";
public POS_System(String amt) {
initComponents();
this.val = amt;
jTextArea1.setText(amt);
}
private void jValueActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Amounts at = new Amounts ();
at.setVisible(true);
at.setLocationRelativeTo(null);
at.txtField.getText();
jTextArea1.setText(at.txtField.getText());
}
// Variables declaration - do not modify
private javax.swing.JButton jTextArea1;
private javax.swing.JButton jEnter;