当前位置: 技术问答>java相关
奇怪的问题?
来源: 互联网 发布时间:2015-10-24
本文导语: f (txtOptName.getText().trim().equals("")) { JOptionPane.showConfirmDialog(this,"操作员名不能为空","",JOptionPane.DEFAULT_OPTION); return false; } else...
f (txtOptName.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this,"操作员名不能为空","",JOptionPane.DEFAULT_OPTION);
return false;
}
else
return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtLoginName.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this,"操作员名不能为空","",JOptionPane.DEFAULT_OPTION);
return false;
}
else
return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtPassWord.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this,"操作员名不能为空","",JOptionPane.DEFAULT_OPTION);
return false;
}
else
return true;
//这样的语句怎么还出错?
JOptionPane.showConfirmDialog(this,"操作员名不能为空","",JOptionPane.DEFAULT_OPTION);
return false;
}
else
return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtLoginName.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this,"操作员名不能为空","",JOptionPane.DEFAULT_OPTION);
return false;
}
else
return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtPassWord.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this,"操作员名不能为空","",JOptionPane.DEFAULT_OPTION);
return false;
}
else
return true;
//这样的语句怎么还出错?
|
你是不是直接写在按钮的一个内部类中了?
下面是我的程序,你看一下。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextDialog extends JFrame {
JTextField txtOptName = new JTextField();
JTextField txtLoginName = new JTextField();
JTextField txtPassWord = new JTextField();
JButton button = new JButton("提交");
TextDialog() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
button_actionPerformed(ae);
}
});
Container contpane = this.getContentPane();
contpane.setLayout(null);
txtOptName.setBounds(20, 30, 100, 21);
txtLoginName.setBounds(20, 61, 100, 21);
txtPassWord.setBounds(20, 92, 100, 21);
button.setBounds(20, 123, 100, 21);
contpane.add(txtOptName);
contpane.add(txtLoginName);
contpane.add(txtPassWord);
contpane.add(button);
setSize(400, 300);
setLocation(200, 50);
}
public static void main(String[] args) {
TextDialog td = new TextDialog();
td.show();
}
public void button_actionPerformed(ActionEvent ae) {
if (txtOptName.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this, "操作员名不能为空", "", JOptionPane.DEFAULT_OPTION);
//return false;
}
//else
//return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtLoginName.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this, "操作员名不能为空", "", JOptionPane.DEFAULT_OPTION);
//return false;
}
//else
//return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtPassWord.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this, "操作员名不能为空", "", JOptionPane.DEFAULT_OPTION);
//return false;
}
//else
//return true;
}
}
下面是我的程序,你看一下。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextDialog extends JFrame {
JTextField txtOptName = new JTextField();
JTextField txtLoginName = new JTextField();
JTextField txtPassWord = new JTextField();
JButton button = new JButton("提交");
TextDialog() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
button_actionPerformed(ae);
}
});
Container contpane = this.getContentPane();
contpane.setLayout(null);
txtOptName.setBounds(20, 30, 100, 21);
txtLoginName.setBounds(20, 61, 100, 21);
txtPassWord.setBounds(20, 92, 100, 21);
button.setBounds(20, 123, 100, 21);
contpane.add(txtOptName);
contpane.add(txtLoginName);
contpane.add(txtPassWord);
contpane.add(button);
setSize(400, 300);
setLocation(200, 50);
}
public static void main(String[] args) {
TextDialog td = new TextDialog();
td.show();
}
public void button_actionPerformed(ActionEvent ae) {
if (txtOptName.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this, "操作员名不能为空", "", JOptionPane.DEFAULT_OPTION);
//return false;
}
//else
//return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtLoginName.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this, "操作员名不能为空", "", JOptionPane.DEFAULT_OPTION);
//return false;
}
//else
//return true;
//提示(在if上):"EditOpt.java": Error #: 550 : statement not reachable at line 133, column 6
if (txtPassWord.getText().trim().equals("")) {
JOptionPane.showConfirmDialog(this, "操作员名不能为空", "", JOptionPane.DEFAULT_OPTION);
//return false;
}
//else
//return true;
}
}