hey m developing a program which is based on swing. i want to open a new form when i select a radio button. i have done coding for this. but when new form opens my code gets hang. i don't know what to do for this...:(sweat)::(-:
plz help me as soon as possible.
i need to submit it at my college..
m posting u my code here.
problem is with File Transfer Radio button...
Code:package FileTransferServer;
import java.net.*;
import java.awt.Desktop;
import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class FTPServer {
public FTPServer() {
DataInputStream din;
DataOutputStream dout;
BufferedReader br;
int port;
ServerSocket server_socket;
String fileName;
port = 6666;
try {
server_socket = new ServerSocket(port);
FileInformationForm.txtInforamtion.append("\nServer waiting for client on port " + server_socket.getLocalPort());
// server infinite loop
while(true) {
Socket socket = server_socket.accept();
FileInformationForm.txtInforamtion.append("\nNew connection accepted "+socket.getInetAddress()+":"+socket.getPort());
din=new DataInputStream(socket.getInputStream());
dout=new DataOutputStream(socket.getOutputStream());
br=new BufferedReader(new InputStreamReader(System.in));
try {
byte[] b = new byte[1024];
int len=0;
int bytcount=1024;
String FileName="ftptest.pdf";
InputStream is = socket.getInputStream();
BufferedInputStream in2 = new BufferedInputStream(is,1024);
fileName=din.readUTF();
FileInformationForm.txtInforamtion.append("\nFile Name : "+fileName);
FileInformationForm.txtInforamtion.append("\nComputer Name : "+din.readUTF());
FileInformationForm.txtInforamtion.append("\nTime : "+din.readUTF());
FileOutputStream inFile ;
File file = new File(fileName);
int option = JOptionPane.showConfirmDialog(FTPServerMain.desk,"File Received Save Disk?");
if(option == JOptionPane.YES_OPTION){
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.showOpenDialog(FTPServerMain.desk);
inFile = new FileOutputStream(chooser.getSelectedFile()+"\\"+fileName);
while( (len = in2.read(b,0,1024)) != -1 ) {
bytcount=bytcount+1024;
inFile.write(b,0,1024);
}
in2.close();
inFile.close();
FileInformationForm.txtInforamtion.append("\nBytes Writen : "+bytcount);
FileInformationForm.txtInforamtion.append("\nFile Transferred Successfully");
}
else {
inFile = new FileOutputStream("tmp"+"\\"+fileName);
while( (len = in2.read(b,0,1024)) != -1 ) {
bytcount=bytcount+1024;
inFile.write(b,0,1024);
}
in2.close();
inFile.close();
/* FileInformationForm.txtInforamtion.append("\nBytes Writen : "+bytcount);
File fileInput = new File(fileName);
Desktop dsk = Desktop.getDesktop();
dsk.open(fileInput);*/
}
}
catch(IOException e) {
FileInformationForm.txtInforamtion.append("\nUnable to open file" + e);
return;
}
try {
File fileInput = new File(fileName);
if(fileInput.exists()) {
}
}
catch (Exception e) {
FileInformationForm.txtInforamtion.append("EXception "+e);
}
}
}
catch (IOException e) {
FileInformationForm.txtInforamtion.append("EXception "+e);
}
}
}
Code:package FileTransferServer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import serverside.*;
public class FTPServerMain extends JFrame implements ActionListener{
static final long serialVersionUID = 101;
static JDesktopPane desk;
public FTPServerMain() {
desk = new JDesktopPane();
setJMenuBar(setMenuBar());
setContentPane(desk);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1020,730);
setVisible(true);
desk.add(new FileInformationForm());
//ServerSideApp.getApplication().hide(null);
FTPServer fTPServer = new FTPServer();
}
public static void main(String[] arc) {
FTPServerMain fTPServerMain = new FTPServerMain();
}
public void actionPerformed(ActionEvent ae) {
if(ae.getActionCommand().equals("Exit")){
System.exit(0);
}
}
private JMenuBar setMenuBar() {
JMenuBar mbr = new JMenuBar();
JMenu mnuFile;
JMenuItem mnuExit;
mnuFile = new JMenu("File");
mnuExit = new JMenuItem("Exit",'x');
mnuFile.add(mnuExit);
mnuFile.setMnemonic('f');
mbr.add(mnuFile);
mnuExit.addActionListener(this);
return mbr;
}
}
this is my code which gets hang when i call it via another form.Code:package FileTransferServer;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class FileInformationForm extends JInternalFrame{
static final long serialVersionUID = 101;
static JTextArea txtInforamtion;
JScrollPane pane;
public FileInformationForm() {
toInitialize();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((dim.width-600)/2,(dim.height-510)/2,600,510);
setTitle("File Information");
setVisible(true);
}
private void toInitialize() {
txtInforamtion = new JTextArea();
pane = new JScrollPane(txtInforamtion);
getContentPane().setLayout(null);
getContentPane().add(pane);
txtInforamtion.setBackground(Color.black);
txtInforamtion.setForeground(Color.green);
txtInforamtion.setEditable(false);
pane.setBorder(new CompoundBorder(new TitledBorder("FileInformation"),new EtchedBorder()));
pane.setBounds(50,100, 500,300);
}
}
plz tell me what wrong wid this or what should i do?

