Javax.Swing; How can I create an object of a different class and assign
variables received from the jframe ? Conceptual issue
I am working for the first time with javax.swing and jframes, so please
excuse me if you find this question primitive.
Problem: In my main function I have created an object of a class lets say
ClassTest. So the code goes like:
import TestPackage.ClassTest.*;
public class Qinterface extends JFrame and implements ActionListener
{
public string Login;
public static void main(String[] args){
ClassTest test = new ClassTest();
try{ eventqueue invoker ...}catch{}
}
Qinterface(){
setResizable(false);
setTitle("Carrefour : Qualys Application");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(300, 100, 850, 500);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
txtEnterText = new JTextField();
txtEnterText.setText("Enter Qualys Login");
txtEnterText.setBounds(10, 193, 166, 23);
contentPane.add(txtEnterText);
txtEnterText.setColumns(10);
btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent eSubmit)
{
//button is pressed
System.out.println("You clicked the button Submit");
Login = txtEnterText.getText();}});
}
}
So as seen in the last line of the code I am able to get the value from
the txtEnterText field and assign to a local variable "Login". But how do
i go about if I want to assign this value to an instance of a class
created, for example;
test.x=txtEnterText.getText();
I know its not possible in this approach as we are in the constructor the
Qinterface class and the variable of the ClassTest instantiated in the
main are not visible.
So the question is general and conceptual; how do you go about such kinds
of problems to resolve them, when coding with javax.swing ?
No comments:
Post a Comment