import javax.swing.*;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class Chatroom extends JFrame implements ActionListener
{
JPanel pm,pn,ps,pw,pe,pc;
BorderLayout b;
ObjectOutputStream output;
ObjectInputStream input;
public Chatroom()
{
pm=new JPanel();
pn=new JPanel();
ps=new JPanel();
pw=new JPanel();
pe=new JPanel();
pc=new JPanel();
b=new BorderLayout();
pm.setLayout(b);
pm.add(pn,BorderLayout.NORTH);
pm.add(ps,BorderLayout.SOUTH);
pm.add(pw,BorderLayout.WEST);
pm.add(pe,BorderLayout.EAST);
pm.add(pc,BorderLayout.CENTER);
JLabel lbiaoti=new JLabel("Software 2005(1) Chatroom");
Color c1=new Color(197,248,184);
pn.setBackground(c1);
Color c2=new Color(246,17,50);
lbiaoti.setForeground(c2);
lbiaoti.setFont(new Font("楷体",Font.PLAIN,36));
pn.add(lbiaoti);
Color c3=new Color(249,170,224);
ps.setBackground(c3);
JLabel lmessage=new JLabel("Message:");
ps.add(lmessage);
JTextArea tmessage=new JTextArea(2,30);
//tmessage.addActionListener(this);
ps.add(new JScrollPane(tmessage));
JButton bsend,bquxiao;
bsend.addActionListener(this);
bquxiao.addActionListener(this);
Icon i=new ImageIcon("D:\\tupian\\send.jpg");
bsend=new JButton(i);
bquxiao=new JButton("Cancel");
bsend.setBackground(c3);
ps.add(bsend);
ps.add(bquxiao);
JPanel pw1=new JPanel();
JLabel lname,lpassword;
lname=new JLabel(" Name: ");
lpassword=new JLabel("Password:");
JTextField tname,tpassword;
tname=new JTextField(10);
tpassword=new JTextField(10);
JButton blogin,bcancel;
blogin=new JButton("Login");
bcancel=new JButton("Cancel");
Color c4=new Color(218,247,230);
pw.setBackground(c4);
pw1.setBackground(c3);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
pw1.setLayout(gbl);
JLabel kongge1=new JLabel(" ");
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(kongge1,gbc);
pw1.add(kongge1);
gbc.gridwidth=1;
gbl.setConstraints(lname,gbc);
pw1.add(lname);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(tname,gbc);
pw1.add(tname);
JLabel kongge2=new JLabel(" ");
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(kongge2,gbc);
pw1.add(kongge2);
gbc.gridwidth=1;
gbl.setConstraints(lpassword,gbc);
pw1.add(lpassword);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(tpassword,gbc);
pw1.add(tpassword);
JLabel kongge3=new JLabel(" ");
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(kongge3,gbc);
pw1.add(kongge3);
gbc.gridwidth=1;
gbl.setConstraints(blogin,gbc);
pw1.add(blogin);
JLabel kongge4=new JLabel(" ");
gbl.setConstraints(kongge4,gbc);
pw1.add(kongge4);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(bcancel,gbc);
pw1.add(bcancel);
pw.add(pw1);
JTextArea tac=new JTextArea(29,45);
Color c5=new Color(156,236,244);
pc.setBackground(c5);
/* JScrollBar bar=new JScrollBar(Adjustable.VERTICAL,0,0,0,0);
bar.addAdjustmentListener(this);*/
// tac.setEditable(false);
pc.add(new JScrollPane(tac));
JTextArea tae=new JTextArea(29,13);
pe.setBackground(Color.getHSBColor(248,248,206));
pe.add(new JScrollPane(tae));
this.getContentPane().add(pm);
this.setSize(870,670);
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e1)
{
if(e1.getSource()==bsend)
{
String message=tmessage.getText();
if(message.length()!=0)
{
output.writeObject("Say:"+message);
output.flush();
tac.append("\nSay:"+message);
tmessage.setText("");
}
else
{
getAppletContext().showStatus("Message Can not be empty!");
}
}
else if(evt.getSource()==tmessage)
{
output.writeObject("Say:"+evt.getActionCommand());
output.flush();
display.append("\nSay>>>"+evt.getActionCommand());
tmessage.setText("");
}
}
public static void main(String args[])
{
Chatroom obj=new Chatroom();
}
}
找不出错在那里了?
[求助]一点小问题哈!