I am working with two JFrames, POS & Amounts. when I click the Value button on POS frame it calls the Amount class for me to enter value(#) in there and when I click on ENTER those values should be transferred back to the textarea in POS frame. I can get the text to appear within the text area by creating a new object of POS jframe, what I want to do is put the values back into the original POS frame that is already open.
See code below...
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;
}
The POS class code:
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;