Advertisement
ferrynurr

XML-RPC SERVER

Oct 25th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.15 KB | None | 0 0
  1. package xmlrpc_hitungberat;
  2. import java.awt.Color;
  3. import java.net.InetAddress;
  4. import java.time.*;
  5. import java.time.temporal.ChronoUnit;
  6. import org.apache.xmlrpc.*;
  7. /**
  8.  *
  9.  * @author ferry
  10.  */
  11. public class Server_Gui extends javax.swing.JFrame {
  12.  
  13.     /**
  14.      * Creates new form Server_Gui
  15.      */
  16.     public Server_Gui() {
  17.         initComponents();
  18.     }
  19.    
  20.  public double hitung_tinggi(String jkel, double tinggi) {
  21.      double ideal;
  22.      double bbi = 0;
  23.      if(jkel.equals("pria")){
  24.         ideal = (tinggi - 100);
  25.         bbi = (ideal -(0.10 * ideal));
  26.       }
  27.      else if(jkel.equals("wanita")){
  28.            ideal = (tinggi - 100);
  29.            bbi = (ideal -(0.15 * ideal));
  30.       }
  31.      
  32.     return bbi;
  33.  }
  34.  
  35.   public double hitung_imt(double tinggi_imt, double berat) {
  36.    
  37.      double konv , imt ;
  38.      
  39.      konv = (tinggi_imt / 100); // konversi dari centimeter ke meter
  40.      imt = berat / (konv * konv);
  41.     return imt;
  42.  }
  43.  
  44.  
  45.     /**
  46.      * This method is called from within the constructor to initialize the form.
  47.      * WARNING: Do NOT modify this code. The content of this method is always
  48.      * regenerated by the Form Editor.
  49.      */
  50.     @SuppressWarnings("unchecked")
  51.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  52.     private void initComponents() {
  53.  
  54.         jPanel1 = new javax.swing.JPanel();
  55.         jLabel1 = new javax.swing.JLabel();
  56.         lisen_port = new javax.swing.JTextField();
  57.         jLabel2 = new javax.swing.JLabel();
  58.         jScrollPane1 = new javax.swing.JScrollPane();
  59.         msg = new javax.swing.JTextArea();
  60.         jLabel3 = new javax.swing.JLabel();
  61.         jButton1 = new javax.swing.JButton();
  62.         jLabel4 = new javax.swing.JLabel();
  63.         handler = new javax.swing.JTextField();
  64.  
  65.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  66.  
  67.         jPanel1.setBackground(new java.awt.Color(0, 0, 0));
  68.  
  69.         jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
  70.         jLabel1.setForeground(new java.awt.Color(255, 255, 255));
  71.         jLabel1.setText("PORT :");
  72.  
  73.         lisen_port.setText("1234");
  74.  
  75.         jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  76.         jLabel2.setForeground(new java.awt.Color(255, 255, 255));
  77.         jLabel2.setText("XML- RPC SERVER");
  78.  
  79.         msg.setColumns(20);
  80.         msg.setRows(5);
  81.         jScrollPane1.setViewportView(msg);
  82.  
  83.         jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
  84.         jLabel3.setForeground(new java.awt.Color(255, 255, 255));
  85.         jLabel3.setText("Log :");
  86.  
  87.         jButton1.setBackground(new java.awt.Color(255, 0, 0));
  88.         jButton1.setText("Run");
  89.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  90.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  91.                 jButton1ActionPerformed(evt);
  92.             }
  93.         });
  94.  
  95.         jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
  96.         jLabel4.setForeground(new java.awt.Color(255, 255, 255));
  97.         jLabel4.setText("HANDLER :");
  98.  
  99.         handler.setText("kunci");
  100.  
  101.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  102.         jPanel1.setLayout(jPanel1Layout);
  103.         jPanel1Layout.setHorizontalGroup(
  104.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  105.             .addGroup(jPanel1Layout.createSequentialGroup()
  106.                 .addContainerGap()
  107.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  108.                     .addGroup(jPanel1Layout.createSequentialGroup()
  109.                         .addComponent(jLabel3)
  110.                         .addGap(0, 0, Short.MAX_VALUE))
  111.                     .addGroup(jPanel1Layout.createSequentialGroup()
  112.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  113.                             .addComponent(jScrollPane1)
  114.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  115.                                 .addComponent(jLabel1)
  116.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  117.                                 .addComponent(lisen_port, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
  118.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
  119.                                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  120.                                     .addComponent(jLabel2)
  121.                                     .addGroup(jPanel1Layout.createSequentialGroup()
  122.                                         .addComponent(jLabel4)
  123.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  124.                                         .addComponent(handler, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
  125.                                         .addGap(32, 32, 32)
  126.                                         .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))))
  127.                         .addContainerGap())))
  128.         );
  129.         jPanel1Layout.setVerticalGroup(
  130.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  131.             .addGroup(jPanel1Layout.createSequentialGroup()
  132.                 .addGap(18, 18, 18)
  133.                 .addComponent(jLabel2)
  134.                 .addGap(22, 22, 22)
  135.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  136.                     .addComponent(jLabel1)
  137.                     .addComponent(lisen_port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  138.                     .addComponent(jLabel4)
  139.                     .addComponent(handler, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  140.                     .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
  141.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
  142.                 .addComponent(jLabel3)
  143.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  144.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
  145.                 .addContainerGap())
  146.         );
  147.  
  148.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  149.         getContentPane().setLayout(layout);
  150.         layout.setHorizontalGroup(
  151.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  152.             .addGroup(layout.createSequentialGroup()
  153.                 .addContainerGap()
  154.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  155.                 .addContainerGap())
  156.         );
  157.         layout.setVerticalGroup(
  158.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  159.             .addGroup(layout.createSequentialGroup()
  160.                 .addContainerGap()
  161.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  162.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  163.         );
  164.  
  165.         pack();
  166.     }// </editor-fold>                        
  167.  
  168.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  169.            
  170.                LocalTime waktu = ZonedDateTime.now().toLocalTime().truncatedTo(ChronoUnit.SECONDS);
  171.         try {
  172.                
  173.                 int port = Integer.parseInt(lisen_port.getText());
  174.                 String handle = handler.getText();
  175.                
  176.                 WebServer server = new WebServer(port);
  177.                 server.addHandler(handle, new Server_Gui());
  178.                 server.start();
  179.                 jButton1.setText("Running..");
  180.                 jButton1.setBackground(Color.green);    
  181.                 msg.append(waktu+" |\tServer XML-RPC Sukses dijalankan...\n");
  182.                 msg.append(waktu+" |\tServer XML-RPC Handler : "+handle+"\n");
  183.                 msg.append(waktu+" |\tServer XML-RPC Host : http://"+InetAddress.getLocalHost().getHostAddress()+":"+port+"/RPC2\n");
  184.                
  185.                
  186.               } catch (Exception exception) {
  187.                 msg.append(waktu+" |\tserver: " + exception + "\n");
  188.               }
  189.     }                                        
  190.  
  191.     /**
  192.      * @param args the command line arguments
  193.      */
  194.     public static void main(String args[]) {
  195.         /* Set the Nimbus look and feel */
  196.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  197.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  198.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  199.          */
  200.         try {
  201.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  202.                 if ("Nimbus".equals(info.getName())) {
  203.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  204.                     break;
  205.                 }
  206.             }
  207.         } catch (ClassNotFoundException ex) {
  208.             java.util.logging.Logger.getLogger(Server_Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  209.         } catch (InstantiationException ex) {
  210.             java.util.logging.Logger.getLogger(Server_Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  211.         } catch (IllegalAccessException ex) {
  212.             java.util.logging.Logger.getLogger(Server_Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  213.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  214.             java.util.logging.Logger.getLogger(Server_Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  215.         }
  216.         //</editor-fold>
  217.  
  218.         /* Create and display the form */
  219.         java.awt.EventQueue.invokeLater(new Runnable() {
  220.             public void run() {
  221.                 new Server_Gui().setVisible(true);
  222.             }
  223.         });
  224.     }
  225.  
  226.     // Variables declaration - do not modify                    
  227.     private javax.swing.JTextField handler;
  228.     private javax.swing.JButton jButton1;
  229.     private javax.swing.JLabel jLabel1;
  230.     private javax.swing.JLabel jLabel2;
  231.     private javax.swing.JLabel jLabel3;
  232.     private javax.swing.JLabel jLabel4;
  233.     private javax.swing.JPanel jPanel1;
  234.     private javax.swing.JScrollPane jScrollPane1;
  235.     private javax.swing.JTextField lisen_port;
  236.     private javax.swing.JTextArea msg;
  237.     // End of variables declaration                  
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement