关于 format 提示:类型 String 中的方法 format(String, Object[])对于参数(String, String)不适用 15
//TextFieldFrame类packagetext;importjava.awt.FlowLayout;importjava.awt.event.ActionEve...
//TextFieldFrame类
package text;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
public class TextFieldFrame extends JFrame{
private JTextField textField1;
private JTextField textField2;
private JTextField textField3;
private JPasswordField passwordField;
public TextFieldFrame()
{
super("Texting JTextField and JPasswordField");
setLayout(new FlowLayout());
textField1=new JTextField(10);
add(textField1);
textField2=new JTextField("Enter text here");
add(textField2);
textField3=new JTextField("Uneditable text field",21);
add(textField3);
passwordField=new JPasswordField("Hidden text");
add(passwordField);
TextFieldHandler handler=new TextFieldHandler();
textField1.addActionListener((ActionListener) handler);
textField2.addActionListener(handler);
textField3.addActionListener(handler);
passwordField.addActionListener(handler);
}
private class TextFieldHandler implements ActionListener
{
public void actionPerformed(ActionEvent event) {
// TODO 自动生成方法存根
String string="";
if(event.getSource()==textField1)
{
string=String.format("textField1:%s", event.getActionCommand());
}
else if(event.getSource()==textField2)
{
string=String.format("textField2:%s", event.getActionCommand());
}
else if(event.getSource()==textField3)
{
string=String.format("textField3:%s", event.getActionCommand());
}
else if(event.getSource()==passwordField)
{
string = String.format( "passwordField: %s",
new String( passwordField.getPassword() ) );
}
JOptionPane.showMessageDialog(null, string);
}
}
}
//TextFieldTest类
package text;
import javax.swing.*;
public class TextFieldTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
TextFieldFrame textFieldFrame=new TextFieldFrame();
textFieldFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textFieldFrame.setSize(350, 100);
textFieldFrame.setVisible(true);
}
}
请各位帮帮忙 看看如何修改才能正确执行? 谢谢啦 展开
package text;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
public class TextFieldFrame extends JFrame{
private JTextField textField1;
private JTextField textField2;
private JTextField textField3;
private JPasswordField passwordField;
public TextFieldFrame()
{
super("Texting JTextField and JPasswordField");
setLayout(new FlowLayout());
textField1=new JTextField(10);
add(textField1);
textField2=new JTextField("Enter text here");
add(textField2);
textField3=new JTextField("Uneditable text field",21);
add(textField3);
passwordField=new JPasswordField("Hidden text");
add(passwordField);
TextFieldHandler handler=new TextFieldHandler();
textField1.addActionListener((ActionListener) handler);
textField2.addActionListener(handler);
textField3.addActionListener(handler);
passwordField.addActionListener(handler);
}
private class TextFieldHandler implements ActionListener
{
public void actionPerformed(ActionEvent event) {
// TODO 自动生成方法存根
String string="";
if(event.getSource()==textField1)
{
string=String.format("textField1:%s", event.getActionCommand());
}
else if(event.getSource()==textField2)
{
string=String.format("textField2:%s", event.getActionCommand());
}
else if(event.getSource()==textField3)
{
string=String.format("textField3:%s", event.getActionCommand());
}
else if(event.getSource()==passwordField)
{
string = String.format( "passwordField: %s",
new String( passwordField.getPassword() ) );
}
JOptionPane.showMessageDialog(null, string);
}
}
}
//TextFieldTest类
package text;
import javax.swing.*;
public class TextFieldTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
TextFieldFrame textFieldFrame=new TextFieldFrame();
textFieldFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textFieldFrame.setSize(350, 100);
textFieldFrame.setVisible(true);
}
}
请各位帮帮忙 看看如何修改才能正确执行? 谢谢啦 展开
2个回答
2020-02-25
展开全部
我也遇到了,刚解决,加载下JavaSE 1.5以上的环境就行了,如果用Myeclipse编译的话,右键点项目,属性,构建路径,库中添加库,找到JavaSE 1.6,加载下就行了
2011-04-10
展开全部
'+char(60)+'font color=red' +char(62)+'我靠'+char(60)+char(47)+'font'+char(62)+'
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询