都是我的错3

1.KeyListener和Thread一样,都是通过改变paint()中的参数的值从而使对象的动作发生变化。

2.实现KeyListener接口时,也要想线程一样要添加监听事件,否则是不能实现的!与之不同的是,线程只需要添加实现过程的类,而在KeyListener中,不仅要在主面板中添加监听实现过程的类,还要对类本身添加自己的监听事件,这是由Java本身的一些缺陷造成的,这个缺陷最早是由王洋老师告诉我的!

3.无论是实现线程Thread接口还是KeyListener接口,都要通过repaint()函数来重画。

4.如果想在JFrame中去掉标题栏,则可以在构造函数初始化的时候加上this.setUndecorated(true),这样可以实现类似JWindow的效果,有一点很重要的是这句一定要写在this.setVisible(true)之前,否则不但不能实现JWindow的效果,而且还会让主类中设置的其它属性不能显示,因此一定要写在设置可见性的前面。

5.如果只想要一个关闭按钮,而不要最大化和最小化的按钮,则可以在主类中继承JDialog类,这样就只有一个叉了,不过要在默认的关闭中设置为:this.setDefaultCloseOperation(Dispose_ON_CLOSE)或者this.setDefaultCloseOperation(HIDE_ON_CLOSE)。其它的如EXIT_ON_CLOSE或者DO_NOTHING_ON_CLOSE实际上在运行的时候并不能起到作用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
前端页面代码示例(使用jQuery实现): HTML部分: ```html <!-- 题目显示区域 --> <div id="question"> <p id="timu"></p> <input type="text" id="answer" placeholder="请输入答案" /> <button id="submit">提交</button> </div> <!-- 正确/误提示区域 --> <div id="result"></div> <!-- 我的题集区域 --> <div id="error-questions"> <h3>我的题集</h3> <ul id="error-list"></ul> </div> ``` JavaScript部分: ```javascript $(function() { // 随机获取一道题目 $.ajax({ url: "/getQuestion", type: "get", dataType: "json", success: function(data) { $("#timu").text(data.timu); } }); // 提交答案 $("#submit").click(function() { var answer = $("#answer").val(); $.ajax({ url: "/checkAnswer", type: "post", dataType: "json", data: {answer: answer}, success: function(data) { if (data.result == "correct") { $("#result").text("正确"); } else { $("#result").text("误"); } // 更新我的题集 updateErrorQuestions(); } }); }); // 更新我的题集 function updateErrorQuestions() { $.ajax({ url: "/getErrorQuestions", type: "get", dataType: "json", success: function(data) { var errorList = $("#error-list"); errorList.empty(); for (var i = 0; i < data.length; i++) { errorList.append("<li>" + data[i].timu + ",答案:" + data[i].answer + "</li>"); } } }); } }); ``` 后端代码示例(使用Spring+MyBatis实现): Controller部分: ```java @Controller public class QuestionController { @Autowired private QuestionService questionService; // 获取一道随机题目 @RequestMapping("/getQuestion") @ResponseBody public Question getQuestion() { return questionService.getRandomQuestion(); } // 检查答案是否正确 @RequestMapping(value = "/checkAnswer", method = RequestMethod.POST) @ResponseBody public Map<String, String> checkAnswer(@RequestParam("answer") String answer) { Map<String, String> result = new HashMap<String, String>(); if (questionService.checkAnswer(answer)) { result.put("result", "correct"); } else { result.put("result", "wrong"); } return result; } // 获取题集 @RequestMapping("/getErrorQuestions") @ResponseBody public List<Question> getErrorQuestions() { return questionService.getErrorQuestions(); } } ``` Service部分: ```java @Service public class QuestionService { @Autowired private QuestionMapper questionMapper; // 获取一道随机题目 public Question getRandomQuestion() { int total = questionMapper.getTotalQuestions(); int randomIndex = (int) (Math.random() * total); return questionMapper.getQuestionByIndex(randomIndex); } // 检查答案是否正确 public boolean checkAnswer(String answer) { Question question = getRandomQuestion(); boolean result = question.getAnswer().equals(answer); if (result) { question.setMark(0); questionMapper.updateQuestionMark(question); } else { question.setMark(1); questionMapper.updateQuestionMark(question); } return result; } // 获取题集 public List<Question> getErrorQuestions() { return questionMapper.getErrorQuestions(); } } ``` Mapper部分: ```java public interface QuestionMapper { int getTotalQuestions(); Question getQuestionByIndex(int index); void updateQuestionMark(Question question); List<Question> getErrorQuestions(); } ``` 以上代码仅为示例,实际实现中需要根据具体需求进行修改和完善。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值