2013年10月31日星期四

An afternoon did not finish , I hope you can help

From another class to get the contents of the text box , and then display the interface to other classes ? Always returns null

------ Solution ------- -------------------------------------

not what it means ? Still intact ?     
If so, then you certainly do not pass the object in the past . . .     
you just send the code I can help you change it .          
  
public class T4 extends JFrame{

private JPanel mainPanel;
JButton btn;
public static JTextField name;

public T4() {
super("标题");
this.setPreferredSize(new Dimension(660,320));
this.setBounds(0, 0, 660, 320);

mainPanel=new JPanel();
this.setContentPane(mainPanel);

 name=new JTextField(15);
 
 mainPanel.add(name);
 
 btn=new JButton("按我");
 mainPanel.add(btn);
 btn.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
new T3();
}});

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
T4 t4=new T4();
t4.setVisible(true);

}

}
  
  
  

public class T3 {


public T3() {
T4 t=new T4();
System.out.println(t.name.getText());
}

public static void main(String[] args) {
new T3();
}
}
 
how the rest of the show at T3 , their landlord to get it

package com.test;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class T4 extends JFrame {

private JPanel mainPanel;
JButton btn;
public JTextField name;
public T3 t3;

public T4() {
super("标题");
this.setPreferredSize(new Dimension(660, 320));
this.setBounds(0, 0, 660, 320);

mainPanel = new JPanel();
this.setContentPane(mainPanel);

name = new JTextField(15);

mainPanel.add(name);

btn = new JButton("按我");
mainPanel.add(btn);
btn.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
t3.show();
}
});

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
T4 t4 = new T4();
T3 t3 = new T3(t4);
t4.t3=t3;
t4.setVisible(true);

}

}
class T3 {
T4 t4;
    public T3(T4 t4) {
     this.t4=t4;
    }
    public void show(){
     System.out.println(t4.name.getText());
    }
}

------ For reference only ----------------------------------- ----
certainly null ah you are a new object ah
------ For reference only ------------------ ---------------------
the A 's name is set to a global variable
------ For reference only ----- ----------------------------------

how should I do it ? Hope that helps
------ For reference only ------------------------------------ ---
you should first create an A object
A a;
then create b object, a pass inside.
class {
A a;
public B (A a) {
this.a = a;
}
/ / then here you can
a.name.getText ();
/ / a
}
------ For reference only --------------------------------- ------

how should I do it ? Hope that helps  

changed : public static JTestFiled name; on it
------ For reference only ------------------ ---------------------


Is this okay ? You call that B (a) it ?
------ For reference only -------------------------------------- -

  
Is this okay ? You call that B (a) it ?  

public class Test {
public static void main(String[] args) {
A a;
B b = null;
a=new A(b);
b=new B(a);
a.b=b;
System.out.println(a.b.bnum);
System.out.println(a.anum);
}

}
class A{
public B b;
public int anum=1;
public A(B b) {
this.b=b;
}

}
class B{
public A a;
public int bnum=2;
public B(A a) {
this.a=a;
}
}

You see so you can call each other. . In fact, I had the same idea , and you ,
Of course, this is easy to fuzzy logic , not very recommended. Are generally level concepts . .
------ For reference only -------------------------------------- -

    
Is this okay ? You call that B (a) it ?          
  

public class Test {
public static void main(String[] args) {
A a;
B b = null;
a=new A(b);
b=new B(a);
a.b=b;
System.out.println(a.b.bnum);
System.out.println(a.anum);
}

}
class A{
public B b;
public int anum=1;
public A(B b) {
this.b=b;
}

}
class B{
public A a;
public int bnum=2;
public B(A a) {
this.a=a;
}
}
  
You see so you can call each other. . In fact, I had the same idea , and you ,   
Of course, this is easy to fuzzy logic , not very recommended. Are generally level concepts . .  

public int anum = 1; is not that a global variable that? To access the inside of the B , A is not a direct new anum to get a
------ For reference only -------------------- -------------------

      
Is this okay ? You call that B (a) it ?                
    

public class Test {
public static void main(String[] args) {
A a;
B b = null;
a=new A(b);
b=new B(a);
a.b=b;
System.out.println(a.b.bnum);
System.out.println(a.anum);
}

}
class A{
public B b;
public int anum=1;
public A(B b) {
this.b=b;
}

}
class B{
public A a;
public int bnum=2;
public B(A a) {
this.a=a;
}
}
    
You see so you can call each other. . In fact, I had the same idea , and you ,     
Of course, this is easy to fuzzy logic , not very recommended. Are generally level concepts . .          
  
public int anum = 1; is not that a global variable that? To access the inside of the B , A is not a direct new anum to get a  
I'm helpless . . I want to explain to you how to call each other between the two classes . Rather than values ​​.

If I am inside the constructor anum based on the input parameters on the assignment , you can get it re- new one ?
------ For reference only -------------------------------------- -

        
Is this okay ? You call that B (a) it ?                      
      

public class Test {
public static void main(String[] args) {
A a;
B b = null;
a=new A(b);
b=new B(a);
a.b=b;
System.out.println(a.b.bnum);
System.out.println(a.anum);
}

}
class A{
public B b;
public int anum=1;
public A(B b) {
this.b=b;
}

}
class B{
public A a;
public int bnum=2;
public B(A a) {
this.a=a;
}
}
      
You see so you can call each other. . In fact, I had the same idea , and you ,       
Of course, this is easy to fuzzy logic , not very recommended. Are generally level concepts . .                
    
public int anum = 1; is not that a global variable that? To access the inside of the B , A is not a direct new anum to get a          
I'm helpless . . I want to explain to you how to call each other between the two classes . Rather than values ​​.   
  
If I am inside the constructor anum based on the input parameters on the assignment , you can get it re- new one ?  

Oh, temporarily not encountered two objects call each other ha. Since I put in the same place values ​​into them, and in the same place it is necessary to take out ?
------ For reference only -------------------------------------- -
references , each creating an object , each object has its own corresponding public property , and static variables are common to all objects share the static variables. Probably so mean . Rookie seeking enlighten
------ For reference only ----------------------------------- ----

        
Is this okay ? You call that B (a) it ?                      
      

public class Test {
public static void main(String[] args) {
A a;
B b = null;
a=new A(b);
b=new B(a);
a.b=b;
System.out.println(a.b.bnum);
System.out.println(a.anum);
}

}
class A{
public B b;
public int anum=1;
public A(B b) {
this.b=b;
}

}
class B{
public A a;
public int bnum=2;
public B(A a) {
this.a=a;
}
}
      
You see so you can call each other. . In fact, I had the same idea , and you ,       
Of course, this is easy to fuzzy logic , not very recommended. Are generally level concepts . .                
    
public int anum = 1; is not that a global variable that? To access the inside of the B , A is not a direct new anum to get a          
I'm helpless . . I want to explain to you how to call each other between the two classes . Rather than values ​​.   
  
If I am inside the constructor anum based on the input parameters on the assignment , you can get it re- new one ?  

not work that way
------ For reference only ------------------------------- --------

not what it means ? Still intact ?
If so, then you certainly do not pass the object in the past . . .
you just send the code I can help you change it .
------ For reference only -------------------------------------- -

not what it means ? Still intact ?   
If so, then you certainly do not pass the object in the past . . .   
you just send the code I can help you change it .  
public class T4 extends JFrame{

private JPanel mainPanel;
JButton btn;
public static JTextField name;

public T4() {
super("标题");
this.setPreferredSize(new Dimension(660,320));
this.setBounds(0, 0, 660, 320);

mainPanel=new JPanel();
this.setContentPane(mainPanel);

 name=new JTextField(15);
 
 mainPanel.add(name);
 
 btn=new JButton("按我");
 mainPanel.add(btn);
 btn.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
new T3();
}});

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args) {
T4 t4=new T4();
t4.setVisible(true);

}

}



public class T3 {


public T3() {
T4 t=new T4();
System.out.println(t.name.getText());
}

public static void main(String[] args) {
new T3();
}
}

------ For reference only ----------------------------------- ----
Haha I guess the landlord two JVM.
------ For reference only -------------------------------------- -
I guess a good standard .
------ For reference only -------------------------------------- -

indeed accurate . .
not be made ​​after people .
------ For reference only -------------------------------------- -

indeed accurate . .   
not be made ​​after people .  

powerful Yeah , terrible
------ For reference only ------------------------------ ---------
page yet when I sent him back piece of it, only to see his reply to a submission reply , I then made ​​a . Awkward

没有评论:

发表评论