Guest User

Untitled

a guest
Jul 20th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.70 KB | None | 0 0
  1. package klient1_gui;
  2.  
  3. public class GUI extends javax.swing.JFrame {
  4.  
  5.     Thread send;
  6.     Thread receive = new Thread(new ReceiveTheMessage());
  7.     String message;
  8.  
  9.     /*public void sTM() {
  10.      SendTheMessage call = new SendTheMessage();
  11.      call.getTheString(message);
  12.      }*/
  13.     public GUI() {
  14.  
  15.     }
  16.  
  17.     public GUI(String message) {
  18.         send = new Thread(new SendTheMessage());
  19.         this.message = message;
  20.         initComponents();
  21.         receive.start();
  22.     }
  23.  
  24.     public String getThisText() {
  25.         message = getTheText.getText();
  26.         System.out.println("Text: " + message);
  27.         return message;
  28.     }
  29.  
  30.     @SuppressWarnings("unchecked")
  31.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  32.     private void initComponents() {
  33.  
  34.         jPanel1 = new javax.swing.JPanel();
  35.         sendButton = new javax.swing.JButton();
  36.         getTheText = new javax.swing.JTextField();
  37.         jLabel1 = new javax.swing.JLabel();
  38.         jScrollPane2 = new javax.swing.JScrollPane();
  39.         displayText = new javax.swing.JTextArea();
  40.         jLabel2 = new javax.swing.JLabel();
  41.         exitButtom = new javax.swing.JButton();
  42.  
  43.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  44.  
  45.         sendButton.setText("Send The Message!");
  46.         sendButton.addActionListener(new java.awt.event.ActionListener() {
  47.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  48.                 sendButtonActionPerformed(evt);
  49.             }
  50.         });
  51.  
  52.         getTheText.addMouseListener(new java.awt.event.MouseAdapter() {
  53.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  54.                 getTheTextMouseClicked(evt);
  55.             }
  56.         });
  57.         getTheText.addActionListener(new java.awt.event.ActionListener() {
  58.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  59.                 getTheTextActionPerformed(evt);
  60.             }
  61.         });
  62.  
  63.         jLabel1.setText("Witam w komunikatorze kliencie 1");
  64.  
  65.         displayText.setEditable(false);
  66.         displayText.setColumns(20);
  67.         displayText.setRows(5);
  68.         jScrollPane2.setViewportView(displayText);
  69.         displayText.getAccessibleContext().setAccessibleParent(this);
  70.  
  71.         jLabel2.setText("Write something to your Friend");
  72.  
  73.         exitButtom.setText("Wyjscie");
  74.         exitButtom.addActionListener(new java.awt.event.ActionListener() {
  75.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  76.                 exitButtomActionPerformed(evt);
  77.             }
  78.         });
  79.  
  80.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  81.         jPanel1.setLayout(jPanel1Layout);
  82.         jPanel1Layout.setHorizontalGroup(
  83.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  85.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  86.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  87.                         .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  88.                         .addComponent(sendButton, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
  89.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  90.                         .addGap(20, 20, 20)
  91.                         .addComponent(jLabel2)
  92.                         .addGap(0, 0, Short.MAX_VALUE)))
  93.                 .addContainerGap())
  94.             .addGroup(jPanel1Layout.createSequentialGroup()
  95.                 .addContainerGap()
  96.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  97.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  98.                         .addGap(0, 182, Short.MAX_VALUE)
  99.                         .addComponent(jLabel1)
  100.                         .addGap(85, 85, 85)
  101.                         .addComponent(exitButtom))
  102.                     .addGroup(jPanel1Layout.createSequentialGroup()
  103.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  104.                             .addComponent(getTheText)
  105.                             .addComponent(jScrollPane2))
  106.                         .addContainerGap())))
  107.         );
  108.         jPanel1Layout.setVerticalGroup(
  109.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  111.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  112.                     .addComponent(exitButtom)
  113.                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
  114.                 .addGap(47, 47, 47)
  115.                 .addComponent(jLabel2)
  116.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  117.                 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
  118.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  119.                 .addComponent(getTheText, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
  120.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  121.                 .addComponent(sendButton)
  122.                 .addContainerGap())
  123.         );
  124.  
  125.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  126.         getContentPane().setLayout(layout);
  127.         layout.setHorizontalGroup(
  128.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  129.             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  130.         );
  131.         layout.setVerticalGroup(
  132.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  133.             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  134.         );
  135.  
  136.         pack();
  137.     }// </editor-fold>                        
  138.  
  139.     private void sendButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
  140.         send.start();
  141.     }                                          
  142.  
  143.     private void getTheTextActionPerformed(java.awt.event.ActionEvent evt) {                                          
  144.         getTheText.getText();
  145.     }                                          
  146.  
  147.     private void getTheTextMouseClicked(java.awt.event.MouseEvent evt) {                                        
  148.         getTheText.setText("");
  149.     }                                      
  150.  
  151.     private void exitButtomActionPerformed(java.awt.event.ActionEvent evt) {                                          
  152.         // TODO add your handling code here:
  153.         System.exit(0);
  154.     }                                          
  155.  
  156.     // Variables declaration - do not modify                    
  157.     public javax.swing.JTextArea displayText;
  158.     private javax.swing.JButton exitButtom;
  159.     protected static javax.swing.JTextField getTheText;
  160.     private javax.swing.JLabel jLabel1;
  161.     private javax.swing.JLabel jLabel2;
  162.     private javax.swing.JPanel jPanel1;
  163.     private javax.swing.JScrollPane jScrollPane2;
  164.     public javax.swing.JButton sendButton;
  165.     // End of variables declaration                  
  166. }
Advertisement
Add Comment
Please, Sign In to add comment