用JAVA 做聊天室

时间:2012-06-11 16:43:01
【文件属性】:

文件名称:用JAVA 做聊天室

文件大小:2KB

文件格式:TXT

更新时间:2012-06-11 16:43:01

JAVA 聊天室

用JAVA做个简单的聊天室import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Guess extends JApplet implements ActionListener { boolean isGuess = true; Font headlineFont = new Font("Helvetica", Font.BOLD, 20); JTextField Title = new JTextField(" Number Guessing "); JTextField guess = new JTextField("",20); JTextField answer = new JTextField("",20); JButton button=new JButton(" GUESS "); JButton button1=new JButton("TRY AGAIN"); int num=(int)(Math.random()*100); public void init() { Container con = getContentPane(); con.setLayout(new FlowLayout()); //BorderLayout borderWithGap = new BorderLayout(5,1); con.add(Title); Title.setFont(headlineFont); Title.setEditable(false); answer.setEditable(false); con.add(guess); con.add(button); con.add(button1); con.add(answer); button.addActionListener(this); button1.addActionListener(this); button.setEnabled(isGuess); button1.setEnabled(!isGuess); /*Title.setLocation(0,0); guess.setLocation(20,40); answer.setLocation(20,60); button.setLocation(50,40); button1.setLocation(50,60);*/ con.setLocation(100,100); con.setSize(300,300); con.setVisible(true); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); int x=Integer.parseInt(guess.getText()); if (source==button1){ isGuess = true ; button.setEnabled(isGuess); button1.setEnabled(!isGuess); } if (source==button) { isGuess = false; button.setEnabled(isGuess); button1.setEnabled(!isGuess); if (x==num) { answer.setText("Great!good Job!"); } else if (x>num) answer.setText("Sorry! bad luck!Guess a small one!"); else answer.setText("Sorry! bad luck!Guess a large one!"); } } }


网友评论

  • 好吧,没有多大实际用途
  • 写的不全啊,server端。。。
  • 怎么没有server那块的撒?
  • 唉 怎么可以这样 你的程序 是单机版的吧