java中如何将字符一个个显示在文本区上?求各位大侠指点~
各位大侠好,小弟正研究java,属于菜鸟级别,现有一问题想请教:
我想做一个计算器,监听器已经加上,但就是不懂如何将按钮上的字
显示在文本区上,像我们常用的计算器那样,输入一个就显示一个,计算
后将结果显示,求个为大侠指点指点啊~分数伺候着
------最佳解决方案--------------------http://blog.csdn.net/zhaoming262350/article/details/8250807
这儿有一个简单的源代码:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
public class Calculator1 extends JFrame implements ActionListener
{
private JFrame jf;
private JButton[] allButtons;
private JButton clearButton;
private JButton sinButton;
private JButton cosButton;
private JButton tanButton;
// private JButton cotButton;
private JTextField jtf;
private boolean isNew = true;
private String recentOperation = null;
private String recentNum = null;
public Calculator1()
{
/**
* 设置窗口点击关闭按钮能关闭
*/
jf=new JFrame("计算器1.0:JAVA");
jf.addWindowListener(new WindowAdapter()
{
public void windowClosing(){
System.exit(0);
}
});
// 实例化所有的按钮以及编辑栏
allButtons = new JButton[16];
clearButton = new JButton("DEL");
sinButton = new JButton("sin");
cosButton = new JButton("cos");
tanButton = new JButton("tan");
jtf=new JTextField(25);
jtf.setEditable(false);
// jtf.setHorizontalAlignment(alignment)
//给CanterPanel中的按钮添加标识符
String str="123+456-789*0.=/";
for(int i=0;i<allButtons.length;i++)
{
allButtons[i]=new JButton(str.substring(i,i+1));
}
}
public void init(){
//设置布局
jf.setLayout(new BorderLayout());
JPanel northPanel=new JPanel();
JPanel centerPanel=new JPanel();
JPanel southPanel=new JPanel();
northPanel.setLayout(new FlowLayout());
centerPanel.setLayout(new GridLayout(4,4));