;

Welcome, Guest. Please login or register.
Did you miss your activation email?

Username: Password:
Pages: [1]   Go Down

Author Topic: mohon bantuan buat java  (Read 1157 times)

ast_neunzig

  • Cabin Crew
  • *
  • Keong: 0
  • Offline Offline
  • Posts: 16
mohon bantuan buat java
« on: March 24, 2009, 09:38:37 am »

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import javax.swing.JFileChooser;
import java.util.*;



public  class Load extends JFrame implements ActionListener {

JDesktopPane jpLoad = new JDesktopPane ();   
JButton btnSelect = new JButton("..Select File..");
JButton btnSend = new JButton("..Send..");
JButton btnExit = new JButton("..Exit..");

JTextField IP1 = new JTextField();
JTextField IP2 = new JTextField();
JTextField IP3 = new JTextField();
JTextField IP4 = new JTextField();

JLabel IP = new JLabel("IP Address");
JLabel tik1 = new JLabel(".");
JLabel tik2 = new JLabel(".");
JLabel tik3 = new JLabel(".");



public Load(){
   super("File Uploader");
   setSize(300,200);

   btnSelect.setBounds(15,15,270,40);
   btnSend.setBounds(70,150,75,25);
   btnExit.setBounds(155,150,75,25);

   IP.setBounds(15,70,150,25);
   IP1.setBounds(15,110,70,25);
   IP2.setBounds(105,110,70,25);
   IP3.setBounds(195,110,70,25);
   IP4.setBounds(285,110,70,25);

   tik1.setBounds(90,110,10,25);
   tik2.setBounds(180,110,10,25);
   tik3.setBounds(270,110,10,25);

   btnSelect.addActionListener(this);
   btnSend.addActionListener(this);
   btnExit.addActionListener(this);

   jpLoad.add(btnSelect);
   jpLoad.add(btnSend);
   jpLoad.add(btnExit);

   jpLoad.add(IP1);
   jpLoad.add(IP2);
   jpLoad.add(IP3);
   jpLoad.add(IP4);
   
   jpLoad.add(IP);
   jpLoad.add(tik1);
   jpLoad.add(tik2);
   jpLoad.add(tik3);

   getContentPane().add(jpLoad, BorderLayout.CENTER);
   setVisible(true);
}

public void actionPerformed (ActionEvent ae){
   Object obj = ae.getSource();
   if (obj == btnSelect){
      choose();
   }
}

public static void main(String args[])throws IOException{
   new Load();
}

/*void kirim(){
      MulticastSocket socket = new MulticastSocket(8890);
      socket.setTTL((byte)5);
      String txtmsg = "";
      JFileChooser fileChooser = new JFileChooser(".");
      File selectedFile = fileChooser.getSelectedFile();
      
       BufferedReader in=new BufferedReader(new FileReader("test.txt"));
      int c;
      try{
         while((c=in.read())!=-1){
            txtmsg=txtmsg+(char)c;
         }
         
         while(true){
            try{
               byte[] buff = new byte[256];
               String timeofday = txtmsg;
               buff = timeofday.getBytes();
               System.out.println (timeofday);
               InetAddress group = InetAddress.getByName("230.1.1.1");
               DatagramPacket packet = new DatagramPacket(buff,buff.length,group,8890);
               socket.send(packet);
               java.lang.Thread.sleep((long)2000);
            }catch(IOException e){
               e.printStackTrace();
            }catch(InterruptedException e){
               break;
            }
         }
         in.close();
         socket.close();
      }catch(FileNotFoundException e){
         System.err.print("CheckedIOTest: "+e);
         System.exit(-1);
      }catch(IOException e){
         System.err.print("CheckedIOTest: "+e);
         System.exit(-1);
      }
}
*/
void choose(){
   JFileChooser fileChooser = new JFileChooser(".");

    fileChooser.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("Action");

      }
    });
   
    int status = fileChooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION) {
      File selectedFile = fileChooser.getSelectedFile();
      System.out.println(selectedFile.getParent());
      System.out.println(selectedFile.getName());
    } else if (status == JFileChooser.CANCEL_OPTION) {
      System.out.println("canceled");

    }
}

void keluar(){
   
   
}

}


tolong di perbaiki..
masih tahap pengembangan..
Logged




frozenb

  • Special Member
  • Penyelam Unggul
  • *****
  • Keong: 0
  • Offline Offline
  • Posts: 6.841
  • YATTA!! Dapet pasang ava juga...
    • Blog Frozenb
Re: mohon bantuan buat java
« Reply #1 on: March 24, 2009, 10:59:38 am »

mo bikin program apa nih??
gw cuman melihat inputan diambil dari test.txt, abis itu ada jam, tp yg laen masi krg paham....

nanti aja kalo java uda gw install lagi k laptop gw..
Logged

ast_neunzig

  • Cabin Crew
  • *
  • Keong: 0
  • Offline Offline
  • Posts: 16
Re: mohon bantuan buat java
« Reply #2 on: March 24, 2009, 02:20:37 pm »

om mohon bantuannya..
ini program untuk mengupload(transfer) sebuah file..
tapi program ini masih banyak yang eror..

1. MulticastSocket socket = new MulticastSocket(8890);
2. socket.setTTL((byte)5);

jadi jalan cerita program tersebut..waktu saya klik tombol "select file",saya bisa memilih file mana yang mau di transfer..begitu saya klik send seharusnya file tersebut berpindah ke program receiver file...
Logged




Pages: [1]   Go Up