Results 1 to 5 of 5
Thread: code gets hang
- 03-20-2012, 09:54 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
code gets hang
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...
.gif)
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...
Java 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); } } }Java 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.Java 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?
-
Re: code gets hang
Read up on threading and Swing because it looks like you're trying to call long-running tasks on the Swing event thread or EDT which will freeze this thread and cause your application to become completely unresponsive. You can find out more in this tutorial: Concurrency in Swing
- 03-22-2012, 07:16 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Re: code gets hang
thanx but i have followed all the steps mention in this link.. still getting same problem... :(
-
Re: code gets hang
Then show us your most recent SSCCE, and let's see if we can help you out further.
- 03-22-2012, 07:40 PM #5
Similar Threads
-
Need Help Starting GUI for Hang Man (JFrames)
By napoleonrokz in forum New To JavaReplies: 3Last Post: 05-27-2011, 12:19 AM -
What type of hang? and how to fix?
By joshbrigade in forum New To JavaReplies: 2Last Post: 11-06-2009, 10:40 PM -
Read XML from Internet Hang!
By yupingliew in forum NetworkingReplies: 0Last Post: 10-22-2009, 05:56 AM -
Applet hang
By Worlock in forum New To JavaReplies: 2Last Post: 08-10-2009, 06:43 AM -
Web application hang without comm.jar
By chankokchern in forum Java AppletsReplies: 0Last Post: 12-16-2008, 12:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks