Advertisement
droidus

code

Dec 14th, 2011
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.18 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3.  
  4. import javax.swing.JLabel;
  5.  
  6. public class NewJFrame extends javax.swing.JFrame {
  7.  
  8.     /** Creates new form NewJFrame */
  9.     public NewJFrame() {
  10.         initComponents();
  11.     }
  12.  
  13.     /**
  14.      * This method is called from within the constructor to initialize the form.
  15.      * WARNING: Do NOT modify this code. The content of this method is always
  16.      * regenerated by the Form Editor.
  17.      */
  18.     @SuppressWarnings("unchecked")
  19.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  20.     private void initComponents() {
  21.  
  22.         inputScroll = new javax.swing.JScrollPane();
  23.         input = new javax.swing.JTextArea();
  24.         jScrollPane1 = new javax.swing.JScrollPane();
  25.         update1 = new javax.swing.JTextArea();
  26.         sendText = new javax.swing.JButton();
  27.         toggleUser = new javax.swing.JComboBox();
  28.  
  29.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  30.         setName(""); // NOI18N
  31.  
  32.         input.setColumns(20);
  33.         input.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
  34.         input.setLineWrap(true);
  35.         input.setRows(5);
  36.         input.setText("Enter Message");
  37.         input.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  38.         input.setName("input"); // NOI18N
  39.         inputScroll.setViewportView(input);
  40.  
  41.         update1.setColumns(20);
  42.         update1.setRows(5);
  43.         update1.setEditable(false);
  44.         update1.setLineWrap(true);
  45.         jScrollPane1.setViewportView(update1);
  46.  
  47.         sendText.setText("Submit");
  48.         sendText.setName("send"); // NOI18N
  49.         sendText.addActionListener(new java.awt.event.ActionListener() {
  50.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  51.                 sendTextActionPerformed(evt);
  52.             }
  53.         });
  54.  
  55.         toggleUser.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
  56.                 "User 1", "User 2" }));
  57.  
  58.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
  59.                 getContentPane());
  60.         getContentPane().setLayout(layout);
  61.         layout.setHorizontalGroup(layout
  62.                 .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  63.                 .addGroup(
  64.                         javax.swing.GroupLayout.Alignment.TRAILING,
  65.                         layout.createSequentialGroup()
  66.                                 .addContainerGap(342, Short.MAX_VALUE)
  67.                                 .addComponent(sendText).addContainerGap())
  68.                 .addComponent(jScrollPane1,
  69.                         javax.swing.GroupLayout.DEFAULT_SIZE, 409,
  70.                         Short.MAX_VALUE)
  71.                 .addComponent(inputScroll,
  72.                         javax.swing.GroupLayout.DEFAULT_SIZE, 409,
  73.                         Short.MAX_VALUE)
  74.                 .addGroup(
  75.                         javax.swing.GroupLayout.Alignment.TRAILING,
  76.                         layout.createSequentialGroup()
  77.                                 .addContainerGap()
  78.                                 .addComponent(toggleUser,
  79.                                         javax.swing.GroupLayout.PREFERRED_SIZE,
  80.                                         82,
  81.                                         javax.swing.GroupLayout.PREFERRED_SIZE)));
  82.         layout.setVerticalGroup(layout
  83.                 .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84.                 .addGroup(
  85.                         javax.swing.GroupLayout.Alignment.TRAILING,
  86.                         layout.createSequentialGroup()
  87.                                 .addComponent(jScrollPane1,
  88.                                         javax.swing.GroupLayout.DEFAULT_SIZE,
  89.                                         305, Short.MAX_VALUE)
  90.                                 .addPreferredGap(
  91.                                         javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  92.                                 .addComponent(inputScroll,
  93.                                         javax.swing.GroupLayout.PREFERRED_SIZE,
  94.                                         javax.swing.GroupLayout.DEFAULT_SIZE,
  95.                                         javax.swing.GroupLayout.PREFERRED_SIZE)
  96.                                 .addPreferredGap(
  97.                                         javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  98.                                 .addComponent(toggleUser,
  99.                                         javax.swing.GroupLayout.PREFERRED_SIZE,
  100.                                         javax.swing.GroupLayout.DEFAULT_SIZE,
  101.                                         javax.swing.GroupLayout.PREFERRED_SIZE)
  102.                                 .addPreferredGap(
  103.                                         javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  104.                                 .addComponent(sendText)));
  105.  
  106.         sendText.getAccessibleContext().setAccessibleName("");
  107.  
  108.         pack();
  109.     }// </editor-fold>
  110.  
  111.     private void sendTextActionPerformed(java.awt.event.ActionEvent evt) {
  112.  
  113.         String timeStamp, temp;
  114.  
  115.         temp = input.getText() + "\n";
  116.         timeStamp = susie.getTimeStamp().toString();
  117.         if (toggleUser.getSelectedItem().equals("User 1")) {
  118.  
  119.             JLabel label = new JLabel("Image and Text", JLabel.CENTER);
  120.             label = new JLabel("A label");
  121.             label.setFont(new Font("Serif", Font.PLAIN, 14));
  122.             label.setForeground(new Color(0xffffdd));
  123.             label.setVerticalTextPosition(JLabel.BOTTOM);
  124.             label.setHorizontalTextPosition(JLabel.CENTER);
  125.             JLabel label2 = new JLabel("Text-Only Label");
  126.            
  127.             update1.setForeground(Color.red);
  128.             update1.append("User 1 [" + timeStamp + "]: " + temp);
  129.         } else if (toggleUser.getSelectedItem().equals("User 2")) {
  130.             temp = input.getText() + "\n";
  131.             timeStamp = susie.getTimeStamp().toString();
  132.             update1.setForeground(Color.BLUE);
  133.             update1.append("User 2 [" + timeStamp + "]: " + temp);
  134.         }
  135.     }
  136.  
  137.     /**
  138.      * @param args
  139.      *            the command line arguments
  140.      */
  141.     public static void main(String args[]) {
  142.         try {
  143.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
  144.                     .getInstalledLookAndFeels()) {
  145.                 if ("Nimbus".equals(info.getName())) {
  146.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  147.                     break;
  148.                 }
  149.             }
  150.         } catch (ClassNotFoundException ex) {
  151.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
  152.                     java.util.logging.Level.SEVERE, null, ex);
  153.         } catch (InstantiationException ex) {
  154.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
  155.                     java.util.logging.Level.SEVERE, null, ex);
  156.         } catch (IllegalAccessException ex) {
  157.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
  158.                     java.util.logging.Level.SEVERE, null, ex);
  159.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  160.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
  161.                     java.util.logging.Level.SEVERE, null, ex);
  162.         }
  163.         // </editor-fold>
  164.  
  165.         /* Create and display the form */
  166.         java.awt.EventQueue.invokeLater(new Runnable() {
  167.  
  168.             public void run() {
  169.                 new NewJFrame().setVisible(true);
  170.             }
  171.         });
  172.     }
  173.  
  174.     // Variables declaration - do not modify
  175.     private javax.swing.JTextArea input;
  176.     private javax.swing.JScrollPane inputScroll;
  177.     private javax.swing.JScrollPane jScrollPane1;
  178.     private javax.swing.JButton sendText;
  179.     private javax.swing.JComboBox toggleUser;
  180.     private javax.swing.JTextArea update1;
  181.     // End of variables declaration
  182. }
  183.  
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement