Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import javax.swing.JLabel;
- public class NewJFrame extends javax.swing.JFrame {
- /** Creates new form NewJFrame */
- public NewJFrame() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- inputScroll = new javax.swing.JScrollPane();
- input = new javax.swing.JTextArea();
- jScrollPane1 = new javax.swing.JScrollPane();
- update1 = new javax.swing.JTextArea();
- sendText = new javax.swing.JButton();
- toggleUser = new javax.swing.JComboBox();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setName(""); // NOI18N
- input.setColumns(20);
- input.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
- input.setLineWrap(true);
- input.setRows(5);
- input.setText("Enter Message");
- input.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- input.setName("input"); // NOI18N
- inputScroll.setViewportView(input);
- update1.setColumns(20);
- update1.setRows(5);
- update1.setEditable(false);
- update1.setLineWrap(true);
- jScrollPane1.setViewportView(update1);
- sendText.setText("Submit");
- sendText.setName("send"); // NOI18N
- sendText.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- sendTextActionPerformed(evt);
- }
- });
- toggleUser.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
- "User 1", "User 2" }));
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
- getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(layout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- javax.swing.GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addContainerGap(342, Short.MAX_VALUE)
- .addComponent(sendText).addContainerGap())
- .addComponent(jScrollPane1,
- javax.swing.GroupLayout.DEFAULT_SIZE, 409,
- Short.MAX_VALUE)
- .addComponent(inputScroll,
- javax.swing.GroupLayout.DEFAULT_SIZE, 409,
- Short.MAX_VALUE)
- .addGroup(
- javax.swing.GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(toggleUser,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- 82,
- javax.swing.GroupLayout.PREFERRED_SIZE)));
- layout.setVerticalGroup(layout
- .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(
- javax.swing.GroupLayout.Alignment.TRAILING,
- layout.createSequentialGroup()
- .addComponent(jScrollPane1,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- 305, Short.MAX_VALUE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(inputScroll,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(toggleUser,
- javax.swing.GroupLayout.PREFERRED_SIZE,
- javax.swing.GroupLayout.DEFAULT_SIZE,
- javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(
- javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(sendText)));
- sendText.getAccessibleContext().setAccessibleName("");
- pack();
- }// </editor-fold>
- private void sendTextActionPerformed(java.awt.event.ActionEvent evt) {
- String timeStamp, temp;
- temp = input.getText() + "\n";
- timeStamp = susie.getTimeStamp().toString();
- if (toggleUser.getSelectedItem().equals("User 1")) {
- JLabel label = new JLabel("Image and Text", JLabel.CENTER);
- label = new JLabel("A label");
- label.setFont(new Font("Serif", Font.PLAIN, 14));
- label.setForeground(new Color(0xffffdd));
- label.setVerticalTextPosition(JLabel.BOTTOM);
- label.setHorizontalTextPosition(JLabel.CENTER);
- JLabel label2 = new JLabel("Text-Only Label");
- update1.setForeground(Color.red);
- update1.append("User 1 [" + timeStamp + "]: " + temp);
- } else if (toggleUser.getSelectedItem().equals("User 2")) {
- temp = input.getText() + "\n";
- timeStamp = susie.getTimeStamp().toString();
- update1.setForeground(Color.BLUE);
- update1.append("User 2 [" + timeStamp + "]: " + temp);
- }
- }
- /**
- * @param args
- * the command line arguments
- */
- public static void main(String args[]) {
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
- .getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
- java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
- java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
- java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(
- java.util.logging.Level.SEVERE, null, ex);
- }
- // </editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JTextArea input;
- private javax.swing.JScrollPane inputScroll;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JButton sendText;
- private javax.swing.JComboBox toggleUser;
- private javax.swing.JTextArea update1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement