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);
//}
//}
}