swt窗体间怎么进行数据交互?下面一个简单例子,怎么把str传输到另一个窗体显示?同一个包和不同的包呢?
if(text.getText().equals("111"))str="登录成功!";elsestr="登录失败!";将str传到另一个窗口显示。...
if(text.getText().equals("111")) str = "登录成功!";
else str = "登录失败!";
将str传到另一个窗口显示。 展开
else str = "登录失败!";
将str传到另一个窗口显示。 展开
1个回答
展开全部
public class NoteFrame extends JFrame {
private JTextField txt1;
private JButton btn;
public NoteFrame() {
txt1 = new JTextField(10);
btn = new JButton("open subFrame");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new SearchFrame(txt1);
}
});
add(txt1, BorderLayout.NORTH);
add(btn, BorderLayout.CENTER);
setTitle("NoteFrame");
setSize(400, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new NoteFrame();
}
}
class SearchFrame extends JFrame {
private JButton btn;
private JTextField txt;
public SearchFrame(JTextField txt) {
this.txt = txt;
btn = new JButton("ok");
btn.addActionListener(new BtnAction(this.txt));
this.add(this.btn, BorderLayout.CENTER);
setTitle("SearchFrame");
setSize(400, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class BtnAction implements ActionListener {
private JTextField txt;
public BtnAction(JTextField txt) {
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
this.txt.setText("hello world");
}
}
}
private JTextField txt1;
private JButton btn;
public NoteFrame() {
txt1 = new JTextField(10);
btn = new JButton("open subFrame");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new SearchFrame(txt1);
}
});
add(txt1, BorderLayout.NORTH);
add(btn, BorderLayout.CENTER);
setTitle("NoteFrame");
setSize(400, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new NoteFrame();
}
}
class SearchFrame extends JFrame {
private JButton btn;
private JTextField txt;
public SearchFrame(JTextField txt) {
this.txt = txt;
btn = new JButton("ok");
btn.addActionListener(new BtnAction(this.txt));
this.add(this.btn, BorderLayout.CENTER);
setTitle("SearchFrame");
setSize(400, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class BtnAction implements ActionListener {
private JTextField txt;
public BtnAction(JTextField txt) {
this.txt = txt;
}
public void actionPerformed(ActionEvent e) {
this.txt.setText("hello world");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询