/**
*图灵IT教育:品质教育,引领专业人生
*电话:0451-86353890
*QQ:330958122
*/
/**
* 软件开发=框架 + 插入点
* 本UI框架,第15次课,详细讲解,学员都能“自主”写出来!
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UI
{
//TODO:变量“声明”在此
YouXi yx;
窗口 ck = null;
定时器 ds1 = null;
UI()
{
//TODO:程序初始化在此
yx=new YouXi();
yx.chuShi();
ck = new 窗口();
//窗口 宽+2*立体边, 高+2*立体边+标题栏
ck.setSize(5 * 2 + 164, 206 + 2 * 5+20+25);
//设定窗口可见性setVisible true/false
ck.setVisible(true);
//延时的毫秒
ds1 = new 定时器(1000);
}
class 窗口 extends JFrame
{
菜单 cd = null;
面板 mb = null;
窗口监听器 exit = null;
键盘监听器 jp = null;
窗口()
{
jp = new 键盘监听器();
this.addKeyListener(jp);
cd = new 菜单();
this.setJMenuBar(cd);
mb = new 面板();
this.add(mb);
exit = new 窗口监听器();
this.addWindowListener(exit);
this.repaint();
}
class 菜单 extends JMenuBar
{
JMenu dan; //菜单
JMenuItem xiang1; //菜单项
菜单监听器 cdjtq;
菜单()
{
dan = new JMenu("游戏"); //菜单
xiang1 = new JMenuItem("开局"); //菜单项
this.add(dan);
dan.add(xiang1);
cdjtq = new 菜单监听器();
xiang1.addActionListener(cdjtq);
}
class 菜单监听器 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//TODO:菜单事件处理
if (e.getSource() == xiang1)
{
}
}
}
}
class 窗口监听器 extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
ds1.xc.stop();
System.exit(0);
}
}
class 键盘监听器 implements KeyListener
{
//TODO:键盘处理,可加入KeyEvent.VK_XXX
public void keyPressed(KeyEvent e)
{
switch (e.getKeyCode())
{
case KeyEvent.VK_LEFT://左
break;
case KeyEvent.VK_RIGHT://右
break;
case KeyEvent.VK_UP://上
break;
case KeyEvent.VK_DOWN://下
break;
}
repaint();
}
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}
}
class 面板 extends JPanel
{
鼠标监听器 sb = null;
面板()
{
sb = new 鼠标监听器();
this.addMouseListener(sb);
this.addMouseMotionListener(sb);
}
class 鼠标监听器 extends MouseAdapter implements MouseMotionListener
{
public void mousePressed(MouseEvent e)
{
}
public void mouseDragged(MouseEvent e)
{
}
public void mouseMoved(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)//鼠标单击
{
//mx my鼠标的位置
int mx = e.getX();
int my = e.getY();
//鼠标左键 BUTTON1、右键BUTTON3
if (e.getButton() == MouseEvent.BUTTON1)
{
//TODO:鼠标左键单击
yx.tanLei(mx, my);
yx.chongWan(mx, my);
}
if (e.getButton() == MouseEvent.BUTTON3)
{
//TODO:鼠标左键单击
yx.biaoDing(mx, my);
}
repaint();
}
}
public void paint(Graphics g)
{
//g.setColor(Color.BLUE); //设定颜色:RED GREEN BLUE ORANGE WHITE GRAY BLACK PINK
//g.drawRect(左,上,宽,高); //矩形
//g.fillRect(左,上,宽,高); //实心矩形
//g.drawOval(左,上,宽,高); //椭圆
//g.fillOval(左,上,宽,高); //实心椭圆
//Image tu=(new ImageIcon( 路径 )).getImage(); //路径:图片-右键-属性-路径src/
//g.drawImage(tu,x,y,null);
//TODO:绘图在此
yx.xianShi(g);
}
}
}
class 定时器 implements Runnable//实现Runnable接口
{
Thread xc = null;
long jianGe;
定时器(long jianGe)
{
this.jianGe = jianGe;
xc = new Thread(this);
xc.start();
}
public void run()
{
while (true)
{
try
{
xc.sleep(jianGe);
if (this == ds1)
{
//TODO:定时处理
yx.dingShi();
ck.repaint();
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
//main主方法 ,主类的“入口方法”
public static void main(String[] args)
{
new UI();
}
}
局外狗
- 粉丝: 78
- 资源: 1万+
最新资源
- 基于javaweb的网上拍卖系统,采用Spring + SpringMvc+Mysql + Hibernate+ JSP技术
- polygon-mumbai
- Chrome代理 switchyOmega
- GVC-全球价值链参与地位指数,基于ICIO表,(Wang等 2017a)计算方法
- 易语言ADS指纹浏览器管理工具
- 易语言奇易模块5.3.6
- cad定制家具平面图工具-(FG)门板覆盖柜体
- asp.net 原生js代码及HTML实现多文件分片上传功能(自定义上传文件大小、文件上传类型)
- whl@pip install pyaudio ERROR: Failed building wheel for pyaudio
- Constantsfd密钥和权限集合.kt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈