Cho em hỏi làm sao để truyên dữ liệu từ Jdialog sang Jframe thế ạ?
Truyền dữ liệu giữa Jdialog và Jframe
Overload lại constructer của Jrame hoặc sử dụng biến static
anh nói rõ hơn chút được không. biến static em đã thử nhưng không hiểu sao không được?
Em up code của mình lên đi
sr em đi học mới về. code của em đây
public JFrameForm() {
JLabel lblResult = new JLabel(“Result”);
lblResult.setBounds(46, 56, 46, 14);
contentPane.add(lblResult);
txtRest = new JTextField();
txtRest.setBounds(139, 53, 86, 20);
contentPane.add(txtRest);
txtRest.setColumns(10);
JButton btnShowDialog = new JButton("Show Dialog");
btnShowDialog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog di = new dialog();
di.setVisible(true);
String str;
str = di.gettxtNhap();
txtRest.setText(str);
}
});
btnShowDialog.setBounds(99, 107, 146, 23);
contentPane.add(btnShowDialog);
}
}
bên Jdialog có thêm hàm
public String gettxtNhap(){
return txtNhap.getText();
}
nhập vào txtNhap của Jdialog xuất ở txtRest của JFrame .