为什么运行出来不能自动换行??求高手帮助。另有重谢importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.util.*;importjava.lang.*;publicclassGuessimplemen...
为什么运行出来不能自动换行??求高手帮助。另有重谢
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
public class Guess
implements ActionListener{
private JFrame _frame;
private JPanel _panelMain;
private JButton _bntCai;
private JTextField _txtCai;
private JLabel _label;
private JPanel _panelCai;
private JPanel _panelArea;
private JScrollPane _jsp;
private JTextArea _txtArea;
private int _result;
private int _score;
private int n;
private JButton _bntReset;
private isNumeric N;
public Guess(){
_frame=new JFrame();
_panelMain=new JPanel(new BorderLayout());
_panelCai=new JPanel();
_panelArea=new JPanel(new BorderLayout());
_bntCai=new JButton("猜");
_txtCai=new JTextField(5);
_txtArea=new JTextArea();
_label=new JLabel("猜1-10之间任意数字:");
_jsp=new JScrollPane(_panelArea);
_result=new Random().nextInt(10)+1;
_score=100;
n=0;
_bntReset=new JButton("重置");
N=new isNumeric();
_panelCai.add(_label);
_panelCai.add(_txtCai);
_panelCai.add(_bntCai);
_panelCai.add(_bntReset);
_panelArea.add(_txtArea);
_panelMain.add(_panelCai,BorderLayout.NORTH);
_panelMain.add(_jsp,BorderLayout.CENTER);
_txtArea.setLineWrap(true);
_jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
_jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
_frame.setContentPane(_panelMain);
_frame.setBounds(300,300,400,300);
_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_frame.setVisible(true);
_bntReset.addActionListener(this);
_bntCai.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Object source=e.getSource();
if (_bntReset==source){
_txtArea.setText("");
n=0;
_txtCai.setText("");
}
if (_bntCai ==source){
String txt_guess=_txtCai.getText();
// if(isNumeric.isNumeric(txt_guess)){
if (n>9){
_txtArea.setText("你的人品太差,请按重置键重新开始!!");
}else
{
int a=Integer.parseInt(txt_guess);
if (a==_result){n++;
int b=_score-n*10;
_txtArea.setText("你猜了"+n+"次,恭喜你,你猜对了!你得到了"+b+"分"+"\n");
}
if (a>_result){n++;
_txtArea.setText("你猜了"+n+"次,你猜错了!太大了"+"\n");
_txtCai.setText("");
}
if (a<_result>
_txtArea.setText("你猜了"+n+"次,你猜错了!太小了"+"\n");
_txtCai.setText("");
}
}
}//else{
//_txtArea.setText("拜托!!是输入1-10的任意数字");
//}
}
}
能不能详细给我补充下 我是个菜鸟
展开