我写的一个倒数转换程序里面有转换按钮,清空和jTextField1三个部件,现在就是当我按下转换时这个输出不知道该怎么写jTextField1.setText(),他着个括号里面又要是String型这我就不知道该怎么办的!请大家指教指教谢谢
package untitled41;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Frame1 extends JFrame {
private int num1=0;
private int j;
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JTextField jTextField1 = new JTextField();
JButton jButton2 = new JButton(); //Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("转换");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jTextField1.setText("");
jButton2.setText("清空");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
contentPane.add(jButton1, new XYConstraints(51, 60, 65, 31));
contentPane.add(jTextField1, new XYConstraints(158, 80, 193, 30));
contentPane.add(jButton2, new XYConstraints(51, 107, 66, 31));
} //Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
} void jButton1_actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="转换"){
num1=Integer.parseInt(((Choice)e.getSource()).getSelectedItem().trim());
do{
j=num1%10;
num1/=10;
jTextField1.setText();
}while(num1!=0);
}
} void jButton2_actionPerformed(ActionEvent e) {
jTextField1.setText(""); }
}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
package untitled41;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Frame1 extends JFrame {
private int num1=0;
private int j;
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JTextField jTextField1 = new JTextField();
JButton jButton2 = new JButton(); //Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
} //Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setText("转换");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jTextField1.setText("");
jButton2.setText("清空");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
contentPane.add(jButton1, new XYConstraints(51, 60, 65, 31));
contentPane.add(jTextField1, new XYConstraints(158, 80, 193, 30));
contentPane.add(jButton2, new XYConstraints(51, 107, 66, 31));
} //Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
} void jButton1_actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="转换"){
num1=Integer.parseInt(((Choice)e.getSource()).getSelectedItem().trim());
do{
j=num1%10;
num1/=10;
jTextField1.setText();
}while(num1!=0);
}
} void jButton2_actionPerformed(ActionEvent e) {
jTextField1.setText(""); }
}class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}class Frame1_jButton2_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee; Frame1_jButton2_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
解决方案 »
- 线程安全集合类也有例外?
- 书里照搬的程序啊,为什么有问题,求教
- Java Word PDF PPT 读写
- IO求高手详细注释!
- 请问,如何将这段 c#代码翻译成java 的? 100分
- 50分求测试session的结果,大家帮忙,感谢。。。
- java 什么是过滤流和节点流啊?
- 如何处理JScrollBar的鼠标弹起事件?
- 谁知道MySQL的驱动接口程序在那里下载?
- 最简单的helloworld程序怎么出现Exception in thread "main" java.lang.NoClassDefFoundError: sunhello错误?
- 请问,不规则窗体怎么实现
- 玩转JEditorPane的高手进来帮下忙......
if(e.getActionCommand().equals("转换")){
num1=Integer.parseInt(((Choice)e.getSource()).getSelectedItem().trim());
StringBuffer szValue =new StringBuffer();
do{
j=num1%10;
num1/=10;
szValue.append(j);
}while(num1!=0);
jTextField1.setText(szValue.toString());
}
}