• Android重力传感器源码

    import android.app.Service; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.SurfaceHolder.Callback; /** *@author Himi *@Sensor 加速度传感器 ,也称为重力传感器 *@SDK 1.5(api 3)就支持传感器了 *@解释:此传感器不仅对玩家反转手机的动作可以检测到,而且会根据反转手机的程度,得到传感器的值也会不同! */ public class MySurfaceView extends SurfaceView implements Callback, Runnable { private Thread th = new Thread(this); private SurfaceHolder sfh; private Canvas canvas; private Paint paint; private SensorManager sm; private Sensor sensor; private SensorEventListener mySensorListener; private int arc_x, arc_y;// 圆形的x,y位置 private float x = 0, y = 0, z = 0; public MySurfaceView(Context context) { super(context); this.setKeepScreenOn(true); sfh = this.getHolder(); sfh.addCallback(this); paint = new Paint(); paint.setAntiAlias(true); setFocusable(true); setFocusableInTouchMode(true); //通过服务得到传感器管理对象 sm = (SensorManager) MainActivity.ma.getSystemService(Service.SENSOR_SERVICE); sensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);//得到一个重力传感器实例 //TYPE_ACCELEROMETER 加速度传感器(重力传感器)类型。 //TYPE_ALL 描述所有类型的传感器。 //TYPE_GYROSCOPE 陀螺仪传感器类型 //TYPE_LIGHT 光传感器类型 //TYPE_MAGNETIC_FIELD 恒定磁场传感器类型。 //TYPE_ORIENTATION 方向传感器类型。 //TYPE_PRESSURE 描述一个恒定的压力传感器类型 //TYPE_PROXIMITY 常量描述型接近传感器 //TYPE_TEMPERATURE 温度传感器类型描述 mySensorListener = new SensorEventListener() { @Override //传感器获取值发生改变时在响应此函数 public void onSensorChanged(SensorEvent event) {//备注1 //传感器获取值发生改变,在此处理 x = event.values[0]; //手机横向翻滚 //x>0 说明当前手机左翻 x<0右翻 y = event.values[1]; //手机纵向翻滚 //y>0 说明当前手机下翻 y<0上翻 z = event.values[2]; //屏幕的朝向 //z>0 手机屏幕朝上 z<0 手机屏幕朝下 arc_x -= x;//备注2 arc_y += y; } @Override //传感器的精度发生改变时响应此函数 public void onAccuracyChanged(Sensor sensor, int accuracy) { // TODO Auto-generated method stub } }; sm.registerListener(mySensorListener, sensor, SensorManager.SENSOR_DELAY_GAME); //第一个参数是传感器监听器,第二个是需要监听的传感实例 //最后一个参数是监听的传感器速率类型: 一共一下四种形式 //SENSOR_DELAY_NORMAL 正常 //SENSOR_DELAY_UI 适合界面 //SENSOR_DELAY_GAME 适合游戏 (我们必须选这个呀 哇哈哈~) //SENSOR_DELAY_FASTEST 最快 } public void surfaceCreated(SurfaceHolder holder) { arc_x = this.getWidth() / 2 - 25; arc_y = this.getHeight() / 2 - 25; th.start(); } public void draw() { try { canvas = sfh.lockCanvas(); if (canvas != null) { canvas.drawColor(Color.BLACK); paint.setColor(Color.RED); canvas.drawArc(new RectF(arc_x, arc_y, arc_x + 50, arc_y + 50), 0, 360, true, paint); paint.setColor(Color.YELLOW); canvas.drawText("当前重力传感器的值:", arc_x - 50, arc_y-30, paint); canvas.drawText("x=" + x + ",y=" + y + ",z=" + z, arc_x - 50, arc_y, paint); String temp_str = "Himi提示: "; String temp_str2 = ""; String temp_str3 = ""; if (x < 1 && x > -1 && y < 1 && y > -1) { ..................... .....................

    4
    236
    47KB
    2012-01-12
    29
  • java学生成绩管理系统

    package chao.serviceimp; import java.util.List; import chao.dao.KcDao; import chao.daoimp.KcDaoImp; import chao.model.Kcb; import chao.service.KcService; public class KcServiceImp implements KcService { KcDao kcDao=new KcDaoImp(); //根据课程号查询 /* (non-Javadoc) * @see chao.serviceimp.KcService#find(java.lang.String) */ public Kcb find(String kch) { return kcDao.find(kch); } //分页显示课程信息 /* (non-Javadoc) * @see chao.serviceimp.KcService#FindAll(int, int) */ public List FindAll(int pageNow,int pageSize) { return kcDao.findAll(pageNow, pageSize); } //查询一共多少条课程记录 /* (non-Javadoc) * @see chao.serviceimp.KcService#findKcSize() */ public int findKcSize() { return kcDao.findXsSize(); } //添加课程信息 /* (non-Javadoc) * @see chao.serviceimp.KcService#save(chao.model.Kcb) */ public void save(Kcb kc) { kcDao.save(kc); } public void delete(String kch) { kcDao.delete(kch); } public void update(Kcb kc) { kcDao.update(kc); } } ..............................

    5
    198
    10.09MB
    2012-01-12
    10
  • java扫雷源码

    package com.kerence.mine.mineGUI; import java.awt.BorderLayout; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.LinkedList; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JFrame; import com.kerence.mine.data_structure.MineMatrix; import com.kerence.mine.mineGUI.dialog.JEnterNameDialog; import com.kerence.mine.mineGUI.menu.JMineMenuBar; import com.kerence.mine.mine_model.Strategy.MineMatrixSettable; import com.kerence.mine.mine_model.Strategy.PreliminaryLevel; import com.kerence.mine.record.Rank; public class JMineSweeperFrame extends JFrame implements WindowListener { JMineMenuBar menuBar = new JMineMenuBar(); JStatusPanel statusPanel = new JStatusPanel(); JMineMatrixPanel jMineMatrixPanel = new JMineMatrixPanel(); public List<Rank> preliminaryLevelRanks = new LinkedList<Rank>(); public List<Rank> intermediateLevelRanks = new LinkedList<Rank>(); public List<Rank> advancedLevelRanks = new LinkedList<Rank>(); /** * 构造方法 对扫雷界面进行初始化,等级为初级,初始化菜单,添加标题栏图标,等操作 */ public JMineSweeperFrame() { // this.setResizable(false); this.setIconImage(new ImageIcon("./image/icon.gif").getImage()); this.setTitle("扫雷"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setJMenuBar(menuBar); this.add(statusPanel, BorderLayout.NORTH); this.add(jMineMatrixPanel); // 初始为初级 jMineMatrixPanel.addMineSweeperFrame(this); statusPanel.addMineSweeperFrame(this); setGameMode(new PreliminaryLevel()); this.addWindowListener(this); menuBar.setMineSweeperFrame(this); this.setResizable(false); this.pack(); } /** * 设置是否开始游戏 用于表示游戏的开始状态 * * @param b * 游戏开始状态 */ public void setIsFirstDig(boolean b) { isFirstDig = b; } /** * 得到当前游戏模式中的雷的个数 * * @return 当前游戏模式中雷的个数 */ public int getMineCount() { return this.jMineMatrixPanel.getMineCount(); } /** * 得到当前游戏模式中的行数 * * @return 当前游戏模式中的行数 */ public int getRowCount() { return this.jMineMatrixPanel.getRowCount(); } /** * 得到当前游戏模式中的列数 * * @return 当前游戏模式中的列数 */ public int getColumnCount() { return this.jMineMatrixPanel.getColumnCount(); } private boolean isFirstDig = true; private boolean button1Pressed; private boolean button3Pressed; private JMineBlock currentMineBlock; private JMineBlock[][] jMineMatrix; private MineMatrix mineMatrix = new MineMatrix(); /** * 游戏开始 激活状态栏的计时器 */ public void gameCommences() { // 开始计时 this.statusPanel.startsTimer(); // this.jMineMatrixPanel.resetGame();这是不用滴 } /** * 游戏失败 停止状态栏的计时器并将表情设置为哭泣 */ public void gameOver() {// 游戏结束 // 终止游戏 并把笑脸设置为哭泣 this.statusPanel.stopTimer(); this.statusPanel.setFaceCry(); } /** * 游戏完成 刷新雷区界面,全部标上红旗,停止计算器,把状态栏的雷数设置为0,跳出输入姓名对话框,并把姓名,等级,时间记录到集合框架中 */ public void gameComplete() {// 完成游戏 // 终止游戏 并把笑脸设置为快乐 jMineMatrixPanel.refreshMineMatrixPanel(); this.statusPanel.stopTimer(); this.statusPanel.setLEDMineCountLeft(0); this.statusPanel.setFaceHappy(); // 判断是哪个等级的 int time = this.statusPanel.getLEDTime();// 得到计时器上的时间。 // 弹出对话框输入大名。 if (getGameModeName().equals("PreliminaryLevel")) {// 如果是完成初级 String name = getHeorName(); preliminaryLevelRanks.add(new Rank("初级", time, name)); } else if (getGameModeName().equals("IntermediateLevel")) {// 如果是完成中级 String name = getHeorName(); intermediateLevelRanks.add(new Rank("中级", time, name)); } else if (getGameModeName().equals("AdvancedLevel")) {// 如果是完成高级 String name = getHeorName(); advancedLevelRanks.add(new Rank("高级", time, name)); } } /** * 弹出一个对话框显示输入英雄名 * * @return 输入的姓名 */ private String getHeorName() { JEnterNameDialog d = new JEnterNameDialog(); d.showDialog(this); return d.getHeroName(); } /** * 得到当前游戏模式的名称 * 只有四种PreliminaryLevel,IntermediateLevel,AdvancedLevel,SelfDefinedLevel * * @return 模式名称字符串 */ private String getGameModeName() { String str[] = this.getGameMode().split("[.]"); return str[str.length - 1]; } /** * 在雷区上按下左键的操作,将状态置为惊讶 */ public void leftButtonPressedOnMineBlock() { this.statusPanel.setFaceSurprised(); } /** * 得到游戏模式,返回的是游戏模式的包名和类名 */ private String getGameMode() { return this.jMineMatrixPanel.getGameMode(); } /** * 左键在雷区上放开 将表情置为笑脸 */ public void leftButtonReleasedOnMineBlock() { // 在表情上放左键意味着重置游戏 在雷区放左键意味着挖雷 就是把状态栏里的表情变成微笑 this.statusPanel.setFaceSmile(); } /** * 设置游戏模式 * * @param s * 游戏模式对象 */ public void setGameMode(MineMatrixSettable s) {// 设置游戏模式 // 在游戏模式更改和Frame的构造函数中都会调用这个方法 // 将雷区重置 this.statusPanel.setFaceSmile(); this.jMineMatrixPanel.setMineMatrix(s); // 将状态栏重置 // int mineCount = this.jMineMatrixPanel.getMineCount(); // // 初始化剩余雷数 // statusPanel.setLEDMineCountLeft(mineCount); // // 停止计时器 // statusPanel.stopTimer(); resetGame(); ...................... ................

    4
    268
    374KB
    2012-01-09
    15
  • Java象棋源码

    import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.io.*; //主类 public class Chess{ public static void main(String args[]){ new ChessMainFrame("中国象棋:观棋不语真君子,棋死无悔大丈夫"); } } //主框架类 class ChessMainFrame extends JFrame implements ActionListener,MouseListener,Runnable{ //玩家 JLabel play[] = new JLabel[32]; //棋盘 JLabel image; //窗格 Container con; //工具栏 JToolBar jmain; //重新开始 JButton anew; //悔棋 JButton repent; //退出 JButton exit; //当前信息 JLabel text; //保存当前操作 Vector Var; //规则类对象(使于调用方法) ChessRule rule; /** ** 单击棋子 ** chessManClick = true 闪烁棋子 并给线程响应 ** chessManClick = false 吃棋子 停止闪烁 并给线程响应 */ boolean chessManClick; /** ** 控制玩家走棋 ** chessPlayClick=1 黑棋走棋 ** chessPlayClick=2 红棋走棋 默认红棋 ** chessPlayClick=3 双方都不能走棋 */ int chessPlayClick=2; //控制棋子闪烁的线程 Thread tmain; //把第一次的单击棋子给线程响应 static int Man,i; ChessMainFrame(){ new ChessMainFrame("中国象棋"); } /** ** 构造函数 ** 初始化图形用户界面 */ ChessMainFrame(String Title){ //获行客格引用 con = this.getContentPane(); con.setLayout(null); //实例化规则类 rule = new ChessRule(); Var = new Vector(); //创建工具栏 jmain = new JToolBar(); text = new JLabel("欢迎使用象棋对弈系统"); //当鼠标放上显示信息 text.setToolTipText("信息提示"); anew = new JButton(" 新 游 戏 "); anew.setToolTipText("重新开始新的一局"); exit = new JButton(" 退 出 "); exit.setToolTipText("退出象棋程序程序"); repent = new JButton(" 悔 棋 "); repent.setToolTipText("返回到上次走棋的位置"); //把组件添加到工具栏 jmain.setLayout(new GridLayout(0,4)); jmain.add(anew); jmain.add(repent); jmain.add(exit); jmain.add(text); jmain.setBounds(0,0,558,30); con.add(jmain); //添加棋子标签 drawChessMan(); //注册按扭监听 anew.addActionListener(this); repent.addActionListener(this); exit.addActionListener(this); //注册棋子移动监听 for (int i=0;i<32;i++){ con.add(play[i]); play[i].addMouseListener(this); } //添加棋盘标签 con.add(image = new JLabel(new ImageIcon("image\\Main.GIF"))); image.setBounds(0,30,558,620); image.addMouseListener(this); .................... ....................

    4
    183
    678KB
    2012-01-09
    15
  • struts spring hibernate面试题

    struts spring hibernate面试题 struts spring hibernate面试题 struts spring hibernate面试题 struts spring hibernate面试题 struts spring hibernate面试题 struts spring hibernate面试题 struts spring hibernate面试题 struts spring hibernate面试题

    4
    84
    62KB
    2011-06-23
    10
  • JavaScript语言参考.rar

    jsAPI JavaScript语言参考 js帮助文档 JavaScript帮助文档 jsAPI JavaScript语言参考 js帮助文档 JavaScript帮助文档 jsAPI JavaScript语言参考 js帮助文档 JavaScript帮助文档

    0
    73
    583KB
    2011-06-09
    9
  • jquery.rar

    jquery.js,jquery.js,jquery.js,jquery.js,jquery.js,jquery.js,jquery.js

    0
    57
    13KB
    2011-05-05
    0
  • fingerGusset1.2.rar

    package com.skeyedu.fingerGuess; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JRadioButton; import javax.swing.JTextArea; import javax.swing.JTextField; public class MainFrame extends JFrame { private MainFrame fingerGuessing = this; private JButton stone; // 石头 private JButton scissors; // 剪刀 private JButton cloth; // 布 private JButton start; // 开始按钮 private JButton exit; // 退出按钮 private JLabel node; // 出拳提示 private JLabel resultShow; // 结果公布 private JTextArea text; // 游戏进程显示文本 private JPanel jpanel; private JRadioButton radioBut1; //单选按钮,选择模式娱乐 private JRadioButton radioBut2; //竞技模式 private ButtonGroup butGroup; //按钮组 private JTextField jushu; //局数输入文本框 private JButton setMode; //设置模式按钮 private Game game; private GameOper gameOper; public MainFrame() { this.init(); // 调用初始化方法 this.setSize(new Dimension(450, 460)); this.setContentPane(getJpanel()); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setResizable(false); this.setLocation(300, 150); this.setTitle("石头-剪刀-布"); this.setVisible(true); } public void init() { //初始化组件及其位置大小 game = new Game(); gameOper = new GameOper(); node = new JLabel("请单击下面按钮出拳!"); node.setBounds(new Rectangle(30, 60, 200, 30)); stone = new JButton(new ImageIcon("ico/shitou.jpg")); stone.setBounds(new Rectangle(30, 85, 55, 60)); stone.setEnabled(false); scissors = new JButton(new ImageIcon("ico/jiandao.jpg")); scissors.setBounds(new Rectangle(120, 85, 55, 60)); scissors.setEnabled(false); cloth = new JButton(new ImageIcon("ico/bu.jpg")); cloth.setBounds(new Rectangle(210, 85, 55, 60)); cloth.setEnabled(false); resultShow = new JLabel("游戏情况:总局数为"+game.getTotalTime()+",当前模式:"+((game.getGameMode()==0)?"娱乐模式":"竞技模式")); resultShow.setBounds(new Rectangle(30, 145, 500, 30)); text = new JTextArea(); text.setText("游戏进度显示:\n玩家 计算机 结果"); text.setEditable(false); text.setBounds(new Rectangle(30, 175, 400, 200)); start = new JButton("开始"); start.setBounds(new Rectangle(100, 385, 100, 30)); exit = new JButton("退出"); exit.setBounds(new Rectangle(205, 385, 100, 30)); radioBut1 = new JRadioButton("娱乐模式"); radioBut1.setSelected(true); radioBut2 = new JRadioButton("竞技模式"); butGroup=new ButtonGroup(); butGroup.add(radioBut1); butGroup.add(radioBut2); radioBut1.setBounds(new Rectangle(20,10,80,30)); radioBut2.setBounds(new Rectangle(100,10,80,30)); jushu = new JTextField(); jushu.setBounds(new Rectangle(20,40,60,20)); setMode = new JButton("设置局数"); setMode.setBounds(new Rectangle(80, 40, 100, 20)); } private JLabel getNode() { return node; } private JButton getStone() { stone.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { checkAndOutput("石头", 0); } }); return stone; } private JButton getScissors() { scissors.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { checkAndOutput("剪刀", 1); } }); return scissors; } private JButton getCloth() { cloth.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { checkAndOutput("布---", 2); } }); return cloth; } // 结果显示框提示 private JLabel getResultShow() { return resultShow; } // 进程及结果显示文本框 private JTextArea getText() { return text; } // 继续 private JButton getStart() { start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cloth.setEnabled(true); scissors.setEnabled(true); stone.setEnabled(true); text.setText("游戏进度显示:\n玩家 计算机 结果"); start.setText("重新開始"); game.resetGame(); } }); return start; }

    0
    89
    21KB
    2011-04-18
    0
  • jsp课程设计学生课绩管理系统源码

    jsp课程设计学生课绩管理系统源码,包含系统结构图

    4
    409
    433KB
    2010-10-11
    23
  • 100个Java经典编程实例源代码

    100个Java经典编程实例源代码 100个Java经典编程实例源代码 100个Java经典编程实例源代码 初学必备。。。

    4
    69
    12.87MB
    2010-05-18
    10
上传资源赚积分or赚钱