
Sir,
If i have a frame with one text field and two button search and send using java swing .If i am clicking a search button then i want to display the file chooser and i want to display the selected file on the text field of frame and if i am clicking send button i want to send that selected file in to client window. please help me to create this and send me the source code using Java Swing

package classes.SearchFile;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextField;
/**
* @author Ajmal Muhammad P
*
*/
@SuppressWarnings("serial")
public class SearchFile extends JFrame implements ActionListener {
private JTextField textField;
private JButton searchButton, sendButton;
private JFileChooser fileChooser;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new SearchFile();
}
public SearchFile() {
// TODO Auto-generated constructor stub
super("Search File");
textField = new JTextField();
searchButton = new JButton("Search");
sendButton = new JButton("Send");
fileChooser = new JFileChooser();
go();
this.setVisible(true);
}
private void go() {
// TODO Auto-generated method stub
Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setBounds(scrn.width/2 - 250, scrn.height/2 - 35, 500, 70);
this.getContentPane().add(searchButton, BorderLayout.WEST);
this.getContentPane().add(sendButton, BorderLayout.EAST);
this.getContentPane().add(textField);
searchButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae) {
// TODO Auto-generated method stub
Object source = ae.getSource();
if(source == searchButton) {
int choice = fileChooser.showOpenDialog(this);
if(choice == JFileChooser.APPROVE_OPTION) textField.setText(fileChooser.getSelectedFile().getAbsolutePath());
}
else if(source == sendButton) {
// Do what u want here
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.