//大总管
public class Test{
myAwt m = new myAwt();
public static void main(String[] args) {
System.out.println(m.i);
}
}
//另外一个文件的一个类
class myAwt{
private int i=100;
}
------解决方案--------------------
不是很明白楼主的意思,不知道是不是这样,直接传个引用过去
Java code
package MainUI.java;
import javax.swing.*;
import Listener.java.*;
public class MainUI extends JFrame{
private JButton jbtn=null;
private JTextField textField=null; //这里这么写
public MainUI(){
jbtn=new JButton("click me");
textField=new JTextField(10);
Listener ls=new Listener(textField);
jbtn.addActionListener(ls);
//此出省略UI代码若干
}
public static void main(String[] args){
new MainUI();
}
}
package Listener.java;
import javax.swing.*;
import java.awt.event.*;
public class Listener implements ActionListener{
private JTextField textField=null;
public Listener(JTextField tf){
textField=tf;
}
public void actionPerformed(ActionEvent e){
textField.setText("Clicked!");//这里这么写
}
}
------解决方案--------------------