读值我想读从Java中textfied值,但我不能读它 这里是我的代码从文本字段
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.*;
public class TextField extends JDialog {
TextField() {
JFrame frm = new JFrame("SAMPLE PROGRAM");
frm.setBounds(150,150,420,400);
frm.setLayout(null);
Container content = frm.getContentPane();
content.setBackground(Color.cyan);
JTextField text = new JTextField();
text.setBounds(70,25,100,30);
JButton button1, button2;
button1 = new JButton("PROGRAMMER");
button2 = new JButton("USER");
button1.setBounds(270,25,120,50);
button2.setBounds(270,90,120,50);
button1.addActionListener(new ButtonHandler());
button2.addActionListener(new ButtonHandler());
frm.add(button1);
frm.add(button2);
frm.add(text);
frm.setVisible(true);
frm.setResizable(false);
}
public static void main(String[] args) {
new TextField();
}
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
String str = new String();
str = e.getActionCommand();
System.out.println(" " + str);
}
}
}
我尝试以下方法
1.In类文本字段我用button2.addactionlistener.It根据本方法得到的误差
无法指非最终可变文本在不同的方法中定义的内部类内部
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(text.getText().equals("joe"))
2.In类ButtonHandler
它说,文本无法解析
我应该用什么方法来读取文本框,并在类应该在阅读
您能否让您的课程更清晰些,并输入所有必要的代码?第一类没有办法。 – Russell 2012-01-28 10:48:27
为什么所有'>'字符都在代码行之前?今后请多做点努力,那个地段就像狗的早餐一样。 – 2012-01-28 11:07:10
没办法解读基本的java教程/教科书并学习它的内容:-) http://docs.oracle.com/javase/tutorial/index.html – kleopatra 2012-01-28 11:10:21