Guest User

Untitled

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