код`package test;
import javax.swing.JButton;
import javax.swing.JTextField;
public class Test {
private JButton b;
private JTextField t;
private MyFrame f;
public static void main(String[] args) {
Test test = new Test();
test.bb();
test.tt();
test.ff();
}
private void bb(){
b=new JButton("{ff");
ab();
}
private void tt(){
t = new JTextField(10);
}
private void ff(){
f=new MyFrame("ee", 130, 100);
f.add(t);
f.add(b);
}
private void ab(){
Lis l = new Lis(b,t);
b.addActionListener(l);
}
}
package test;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;
public class Lis implements ActionListener{
private JButton b;
private JTextField t;
public Lis (JButton bb, JTextField tt){
b=bb;
t=tt;
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b){
System.out.println(t.getText());
}
}
}
package test;
import java.awt.FlowLayout;
import javax.swing.JFrame;
public class MyFrame extends JFrame{
public MyFrame(String title, int wigth, int higth ){
super.setTitle(title);
super.setSize(wigth, higth);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setLayout(new FlowLayout());
super.setLocationRelativeTo(null);
super.setVisible(true);
}
}
Asked
Active
Viewed 53 times
0
Alex_mur
- 11
1 Answers
0
public static JTextField t; //Замените на статик
if(e.getSource() == b){
System.out.println(Test.t.getText());//Обратитесь так
}
Minepolz320
- 471