用JOptionPane
JOptionPane.showInputDialog()//提问用
JOptionPane.showMessageDialog()//回答用

解决方案 »

  1.   

    用JTextField就可以实现吧,输入一行后触发时间,在事件处理方法中,调用回答算法,把结果JTextField.setText()到textfield上。
      

  2.   

    要颜色不同,可以设置么。jb里面应该有选项(很久不用了记不住怎么写了)api应该在基类里找
      

  3.   

    颜色不是很好实现,这里没有实现。给我一个e-mail,有空把颜色的实现写完给你。
    **********************************************************************
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author unascribed
     * @version 1.0
     */public class Test extends JFrame {
      private JPanel panel1 = new JPanel();
      private JPanel panel2 = new JPanel();
      private JButton okButton = new JButton();
      private JTextField textField = new JTextField();
      private GridBagLayout gridBagLayout1 = new GridBagLayout();
      private BorderLayout borderLayout1 = new BorderLayout();
      private JScrollPane scrollPane = new JScrollPane();
      private JEditorPane edit = new JEditorPane();
      private String answer1="computer";
      private String answer2="computing";
      private String u="U:";
      private String c="C:";
      private static String contains="***********************************************************"+"\n";
      private JButton exitButton = new JButton();
      private JLabel jLabel1 = new JLabel();
      public Test() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        panel1.setBorder(BorderFactory.createEtchedBorder());
        panel1.setLayout(borderLayout1);
        okButton.setText("发送");
        okButton.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            okButton_actionPerformed(e);
          }
        });
        panel2.setLayout(gridBagLayout1);
        panel2.setBorder(BorderFactory.createLoweredBevelBorder());
        edit.setBackground(new Color(212, 208, 200));
        edit.setEditable(false);
        edit.setText(contains);
        textField.requestFocus();
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
        exitButton.setText("退出");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            exitButton_actionPerformed(e);
          }
        });
        jLabel1.setText("命令输入:");
        this.getContentPane().add(panel1,  BorderLayout.CENTER);
        this.getContentPane().add(panel2,  BorderLayout.SOUTH);
        panel2.add(textField,       new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
        panel2.add(okButton,        new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 10, 5, 0), 0, 0));
        panel2.add(exitButton,  new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        panel2.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        panel1.add(scrollPane,  BorderLayout.CENTER);
        scrollPane.getViewport().add(edit, null);  }  void okButton_actionPerformed(ActionEvent e) {    this.appendText(edit.getText(),u+textField.getText());
        if(textField.getText().equalsIgnoreCase("what is your name?")){      this.appendText(edit.getText(),c+answer1);
        }
        if(textField.getText().equalsIgnoreCase("what are you doing?")){
          this.appendText(edit.getText(),c+answer2);    }
        textField.setText("");
        textField.requestFocus();
      }
      private void    appendText(String before_str,String addString){
        edit.setText(before_str+"\n"+addString);
      }
      public static void main(String[] args){
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e) {
          e.printStackTrace();
        }
        Test test=new Test();
        test.setSize(400,300);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = test.getSize();
        if (frameSize.height > screenSize.height) {
          frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
          frameSize.width = screenSize.width;
        }
        test.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        test.setVisible(true);
        test.setTitle("测试") ;
        test.show();  }  void exitButton_actionPerformed(ActionEvent e) {
        System.exit(0);
      }
    }
    ************************************************************************
      

  4.   

    搂住是要做qq那种还是谈对话框的那种呢?用JOptionPane
    JOptionPane.showInputDialog()//提问用
    JOptionPane.showMessageDialog()//回答用  这个答案是做对话框的。
    如果是要做qq那种,只需要JButton JTextArea就行了。