java文本域换行_java 文本域自动换行问题

为什么运行出来不能自动换行??求高手帮助。另有重谢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的任意数字");

//}

}

}

能不能详细给我补充下 我是个菜鸟

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值