java窗体猜数字代码import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class caishuzi extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
private JPanel textpanel, buttonpanel, fopanel, downpanel;
private JButton btn;
private JTextField jtinput, jttishi;
private JLabel lbnum0, lbnum, lbtishi, lbinput;
private JTextArea tafo;
private Boolean start = false, jisuan = false, jinru = false;
MenuBar mb = new MenuBar();
Menu filemenu = new Menu("文件"), systemmenu = new Menu("系统"),
helpmenu = new Menu("帮助");
MenuItem newfile = new MenuItem("文件"), openfile = new MenuItem("打开"),
closefile = new MenuItem("关闭"), quit = new MenuItem("退出"),
inputsecret = new MenuItem("输入密码"), help = new MenuItem("帮助"),
inputcishu = new MenuItem("输入限制次数");
char[] c = new char[4];
String strsecret = "123";
int xianzhi=8;
caishuzi()
{
super("猜数字");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.setLocationRelativeTo(null);
// 设置菜单
filemenu.add(newfile);
filemenu.add(openfile);
filemenu.addSeparator();
filemenu.add(closefile);
newfile.setEnabled(false);
openfile.setEnabled(false);
closefile.setEnabled(false);
inputsecret.addActionListener(this);
inputcishu.addActionListener(this);
inputcishu.setEnabled(false);
systemmenu.add(inputsecret);
systemmenu.add(inputcishu);
systemmenu.add(quit);
quit.addActionListener(this);
help.addActionListener(this);
helpmenu.add(help);
mb.add(filemenu);
mb.add(systemmenu);
mb.add(helpmenu);
this.setMenuBar(mb);
Container c = this.getContentPane();
BorderLayout b = new BorderLayout();
b.setVgap(10);
c.setLayout(b);
settextpanel();
c.add(textpanel, BorderLayout.NORTH);
setbuttonpanel();
setfopanel();
setdownpanel();
c.add(downpanel, BorderLayout.CENTER);
this.setSize(680,350);
//this.setResizable(false);
//this.pack();
this.setVisible(true);
}
void settextpanel()
{
textpanel = new JPanel();
textpanel.setLayout(new FlowLayout());
lbinput = new JLabel("输入:");
jtinput = new JTextField("", 10);
jtinput.setEditable(false);
jttishi = new JTextField(30);
lbnum = new JLabel("8");
lbnum0 = new JLabel("剩余次数:");
lbtishi = new JLabel("提示:");
jttishi.setEditable(false);
textpanel.add(lbinput);
textpanel.add(jtinput);
textpanel.add(lbtishi);
textpanel.add(jttishi);
textpanel.add(lbnum0);
textpanel.add(lbnum);
}
void setbuttonpanel()
{
String[] str =
{ "7", "8", "9", "4", "5", "6", "1", "2", "3", "确定", "0", "退格" };
buttonpanel = new JPanel();
buttonpanel.setLayout(new GridLayout(4, 3, 4, 8));
for (int i = 0; istr.length; i++)
{
btn = new JButton(str[i]);
btn.addActionListener(this);
buttonpanel.add(btn);
}
}
void setfopanel()
{
JButton btnright = new JButton("正确答案");
JPanel p = new JPanel();
btnright.addActionListener(this);
fopanel = new JPanel();
fopanel.setLayout(new BorderLayout());
btn = new JButton("开始");
btn.addActionListener(this);
tafo = new JTextArea(15,12);
p.setLayout(new GridLayout(1, 2));
p.add(btn);
p.add(btnright);
fopanel.add(p, BorderLayout.NORTH);
tafo.setEditable(false);
fopanel.add(tafo, BorderLayout.CENTER);
}
void setdownpanel()
{
downpanel = new JPanel();
downpanel.setLayout(new GridLayout(1, 2, 30, 0));
推荐阅读
- 各种卡片制作器下载安卓,卡片制作方法
- 笔电怎么看显卡瓦数,笔记本显卡怎么看多少瓦
- flutter穿戴应用,flutter platform
- 华硕路由器怎么查看账号,华硕路由器怎么查看账号密码
- mysql怎么插入表记录 mysql怎么添加记录
- sqlserver2列和成一列,sqlserver将列拼接
- 好看的动漫游戏桌面,超好玩的动漫游戏
- 头条怎样可以带货直播卖货,怎么在头条直播卖货
- go语言实习文案朋友圈 go语言培训