Number Kingdom 笔记【Java】

Number Kingdom 笔记【Java】

1.引入的常用包
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
2.主程序部分
public class N
{
    public static void main(String[] args)
    {
        Work();
    }
}
3.时间/倒计时
java.util.Timer timer=new java.util.Timer();
MyTime timetask=new MyTime();
public class MyTime extends TimerTask
{
    public void run()
    {
        sec--;
        Work();
        if(sec==0)Over();
    }
}
timer.schedule(timetask,1000,1000);
//timer.schedule(timetask,首次延时,间隔时间);
4.JFrame声明
JFrame table=new JFrame("标题");//JFrame参数可为空
void Set_Table()
    {
        table.setSize(1000,618);//table.setSize(宽度,高度);
        table.setVisible(true);//组件可见
        table.setLayout(null);//自定义布局
        table.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//正常关闭退出
    }
//或table.setLayout(new FlowLayout());即流动布局(默认)
5.JLabel声明
JLabel say=new JLabel("文本内容");//参数可为空
say.setBounds(300,10,200,20);//say.setBounds(横向位置,纵向位置,宽度,高度);
say.setForeground(Color.green);//设置字体颜色
say.setFont(new Font(null,1,15));//设置字体格式 Font(字体,是否加粗,字号)
table.add(say);//加入组件
say.setText("新内容");//重设文本内容
//位置以左上角为原点,以像素为单位

JLabel内嵌HTML语法

//JLabel say21=new JLabel("
//<html>
//&emsp;规则:游戏共五关,通关有惊喜。<br>
//&emsp;&emsp;&emsp;&emsp;每关需在1~200中选择符合题意的数字输入。<br>
//&emsp;&emsp;&emsp;&emsp;输入数字的正误将会显示,每关正确数达到3个时过关。<br>
//&emsp;&emsp;&emsp;&emsp;数字错误一次将损失一点生命值,生命值为0时游戏失败。<br>
//&emsp;提示:游戏中单击可获得提示。<br>
//&emsp;获得提示次数:单击后输入兑换码可获得提示次数。<br>
//");
6.JButton声明
JButton button=new JButton("内容");
button.setBounds(430,10,150,20);
table.add(button);
7.JTextArea声明
JTextArea answer=new JTextArea(1,20);//JTextArea(行数,长度)
table.add(answer);
ans=answer.getText();//获取文本框中文本
8.数组声明
int line[]=new int[205];
int snum[]={0123};
9.按钮事件
button.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent e)
        {
            Work();
        }
    });
10.版权声明模板
void About()
    {
        JFrame table14=new JFrame("关于作者");
        JLabel say19=new JLabel("联系作者:");
        JLabel say18=new JLabel("<html>QQ:997577114<br>E-mail:wfzhangzeyu@163.com");
        JLabel say20=new JLabel("All Rights Reserved By MC");
        table14.setSize(400,200);
        table14.setVisible(true);
        table14.setLayout(null);
        say19.setFont(new Font(null,1,12));
        say19.setBounds(70,15,100,40);
        say18.setFont(new Font(null,0,12)); 
        say18.setBounds(155,20,200,40);
        say20.setBounds(100,70,200,40);
        say20.setFont(new Font(null,1,14));
        table14.add(say18);
        table14.add(say19);
        table14.add(say20);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值