This was for school, and now I want to try and check the string in the TextField against another string, to see if it is the same or not, What should I do? do i need global variables or something?
[code]import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SINProgram{
public static void main(String args[]){
JFrame frame;
Container c;
frame=new JFrame("SIN Program");
c=frame.getContentPane();
c.setLayout(new FlowLayout());
JTextField tfSIN=new JTextField(13);
JLabel lblSIN=new JLabel ("Enter your SIN number");
JLabel lblOutput=new JLabel("");
JButton buttonCheckSIN=new JButton("Check SIN");
c.add(tfSIN);
c.add(lblSIN);
c.add(buttonCheckSIN);
c.add(lblOutput);
MyButtonListener mbl = new MyButtonListener (tfSIN,lblOutput);
buttonCheckSIN.addActionListener(mbl);
frame.setSize(500,100);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end main
}//end class[/code]
And the listener:
[code]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyButtonListener implements ActionListener{
JTextField tf;
JLabel l;
MyButtonListener(JTextField tfNumber, JLabel lblMsg){
tf=tfNumber;
l=lblMsg;
}
public void actionPerformed (ActionEvent e){
l.setText("Hello");
}
}//end class[/code]