求大神帮看一下button事件加if语句就不响应了谢谢!!去掉就可以!

努力加油奥力给 努力加油奥力给 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package 猜数游戏;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class csyx extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel p;
public JButton b1;
public JButton b2;
public JButton b3;
public JButton b4;
private JLabel c1,c2,c3,c4;
public JTextField d1;
public JTextField d2;
public JTextField d3;
public JTextField d4;
private JTextArea e1,e2;
private JMenuBar menuBar;
private JMenu menu,sort;
private JMenuItem rule,exit,time,frequency;
public csyx(){
super("猜数游戏");
p=new JPanel();
p.setLayout(null);
b1=new JButton("确定");
b2=new JButton("显示答案");
b3=new JButton("重新开始");
b4=new JButton("保存");
c1=new JLabel("请输入:");
c2=new JLabel("答案:");
c3=new JLabel();
c4=new JLabel();
/*final*/ JTextField d1=new JTextField();
d2=new JTextField();
d3=new JTextField();
d4=new JTextField();
e1=new JTextArea();
e2=new JTextArea();
menuBar=new JMenuBar();
this.setJMenuBar(menuBar);
menu=new JMenu("菜单");
sort=new JMenu("排序");
rule=new JMenuItem("游戏规则");
exit=new JMenuItem("退出");
time=new JMenuItem("按时间(毫秒)");
frequency=new JMenuItem("按次数");
b1.setBounds(223, 341, 90, 28);
b2.setBounds(95, 308, 90, 28);
b3.setBounds(359, 341, 90, 28);
b4.setBounds(292, 314, 90, 28);
c1.setBounds(10, 346, 72, 24);
c2.setBounds(16, 314, 72, 24);
c3.setBounds(139, 162, 72, 24);
c4.setBounds(139, 25, 72, 24);
d1.setBounds(95, 346, 26, 21);
d2.setBounds(127, 346, 26, 21);
d3.setBounds(159, 346, 26, 21);
d4.setBounds(191, 346, 26, 21);
e1.setBounds(230, 208, 204, 100);
e2.setBounds(0, 10, 94, 112);
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(c1);
p.add(c2);
p.add(c3);
p.add(c4);
p.add(d1);
p.add(d2);
p.add(d3);
p.add(d4);
p.add(e1);
p.add(e2);
menuBar.add(menu);
menu.add(rule);
menu.addSeparator();
menu.add(sort);
menu.addSeparator();
menu.add(exit);
sort.add(time);
sort.add(frequency);
b1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
String s=d1.getText();
if(s==null)
JOptionPane.showMessageDialog(csyx.this.b1,"您没有填写完四位数,请仔细阅读游戏规则,然后重新输入");//,"提示窗口",JOptionPane.ERROR_MESSAGE);
//csyx.this.setVisible(false);
//csyx.this.d1.requestFocus();
return;

}});
e2.setVisible(false);
Icon i=new ImageIcon("D:\\b1ff710676901d4de32661f454240c11.jpg");
JLabel c5=new JLabel(i);
this.getLayeredPane().add(c5, new Integer(Integer.MIN_VALUE));
c5.setBounds(0,0, 450, 430);
p.add(c5);
this.add(p);
this.setSize(450, 430);
this.setLocation(100, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String[] args){
csyx frame=new csyx();
frame.setVisible(true);
}
//class ButtonListener implements ActionListener{
//public void actionPerformed(ActionEvent e){
//String a=d1.getText();
//if (a>1)//||d2.getText()==null||d3.getText()==null||d4.getText()==null)
// JOptionPane.showMessageDialog(null,"您没有填写完四位数,请仔细阅读游戏规则,然后重新输入","提示窗口",JOptionPane.INFORMATION_MESSAGE);

//}
//}
}

...全文

相关推荐

探寻C# Button双击事件

C# Button双击事件大家一定相当熟悉了,本文笔者又再一次为你阐述了C# Button双击事件的原理及实现 方法。 C# Button是有DoubleClick事件的,只是它没有出现在事件列表中,而且.net也是把这个事件给"屏蔽" 掉了,无论你双击一个按钮怎么快,也不会触发这个事件。 为了能够触发C# Button的双击事件,我们可以重载MouseDown事件,记录每次鼠标按下的时间,如果 两次点击的时间足够近的话,就触发一次双击方法。 这样也大致能够达到双击的效果,我所采用的方法其实和这个类似,是继承Button类,重载Button类的 Click事件,在Click事件中判断两次点击的时间,如果近的话,就触发双击事件。

bishuyuan

JS之if语句对接事件动作逻辑(详解)

下面小编就为大家带来一篇JS之if语句对接事件动作逻辑(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38635975

listView上增加button点击事件

这个demo主要解决了在listview上面增加button 是button和item同事拥有点击事件,接觉他们两个事件冲突的问题

cjj821

GridView中添加button后button无响应,和item无响应的解决

解决了GridView中添加button后button无响应,以及button有相应后 原来的item没有响应的问题

我的学生时代

关于verilog中if与case语句不完整产生锁存器的问题

在很多地方都能看到,verilog中if与case语句必须完整,即if要加上else,case后要加上default语句,以防止锁存器的发生,接下来就来说说其中原因。

weixin_38729399
评论 1
收藏 已收藏
分享
返回顶部
努力加油奥力给
Java 51,407 成员 86,128 内容