P. 1
Ventana Chat 2

Ventana Chat 2

|Views: 0|Likes:
Published by Walter Cabrera

More info:

Published by: Walter Cabrera on Nov 14, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

11/14/2013

pdf

text

original

import java.awt.*; import java.awt.event.*; import javax.swing.

*; public class VentanaChat2 extends JFrame implements ActionListener, KeyListener , ItemListener { private JTextArea txtArea; private JScrollPane scrlPane; private JTextField txtTexto; private JButton btnEnviar; private JRadioButton rbtnJuan; private JRadioButton rbtnMaria; private ButtonGroup bgOpciones; public VentanaChat2(){ super("GridBagLayout"); this.setSize(400,400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); txtArea = new JTextArea(); scrlPane = new JScrollPane(txtArea); txtTexto = new JTextField(20); btnEnviar = new JButton("Enviar"); gbc.gridx=0; gbc.gridy=0; gbc.gridwidth = 2 ; gbc.gridheight = 1; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; add(scrlPane, gbc); gbc.gridx=0; gbc.gridy=1; gbc.gridwidth = 1 ; gbc.gridheight = 1; gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.HORIZONTAL; add(txtTexto, gbc); gbc.gridx=1; gbc.gridy=1; gbc.gridwidth = 1 ; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.NONE; add(btnEnviar, gbc); rbtnJuan = new JRadioButton("Juan"); rbtnJuan.addItemListener(this); gbc.gridx=0; gbc.gridy=3;

gridwidth = 1 . gbc. rbtnMaria = new JRadioButton("Maria"). gbc.append("Juan: "+txtTexto. setVisible(true). } if(rbtnMaria. gbc.gridwidth = 1 .NONE. txtTexto. btnEnviar.setText("").gridheight = 1. v. } } @Override public void keyTyped(KeyEvent e) {} @Override . rbtnMaria. gbc.isSelected()){ txtArea.addItemListener(this). txtTexto.0. add(rbtnJuan. } } public static void main (String[] args){ VentanaChat2 v = new VentanaChat2().addKeyListener(this).gbc.0. } @Override public void itemStateChanged(ItemEvent e) { if(rbtnJuan.weighty = 0. gbc. gbc.0. gbc. gbc).getSource() == btnEnviar ){ txtArea. add(rbtnMaria.getText()+"\n"). gbc.gridx=0.0. gbc. gbc.setText("").fill = GridBagConstraints.setVisible(true).weightx = 0.weightx = 0.getText()+"\n").append(txtTexto.weighty = 0. txtTexto.NONE. txtTexto.getText() + "\n"). gbc).isSelected()){ txtArea. } public void actionPerformed(ActionEvent e) { if (e.append("Maria: "+txtTexto. gbc.fill = GridBagConstraints.addActionListener(this).gridy=2.gridheight = 1.setText(""). bgOpciones = new ButtonGroup().

break.getKeyCode()){ case KeyEvent.append(txtTexto.public void keyPressed(KeyEvent e) { switch(e.VK_ENTER: txtArea.setText("").getText()+"\n"). txtTexto. } } public void keyReleased(KeyEvent e) {} } .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->