16.3
2016-07-02 15:51
274 查看
import java.awt.BorderLayout; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Test_16 extends JFrame implements ActionListener{ private JButton j1 = new JButton("left"); private JButton j2 = new JButton("right"); private JButton j3 = new JButton("up"); private JButton j4 = new JButton("down"); private JP j = new JP(); private int x =100,y =200; public Test_16(){ JPanel J = new JPanel(); J.add(j1);J.add(j2);J.add(j3);J.add(j4); j1.addActionListener(this); j2.addActionListener(this); j3.addActionListener(this); j4.addActionListener(this); add(J,BorderLayout.SOUTH); add(j,BorderLayout.CENTER); } public static void main(String[] args) { // TODO Auto-generated method stub Test_16 t1 = new Test_16(); t1.setTitle("Test_16"); t1.setSize(400,400); t1.setFocusable(true); t1.setLocationRelativeTo(null); t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t1.setVisible(true); } class JP extends JPanel{ private int radius = 5; protected void paintComponent(Graphics g){ super.paintComponent(g); g.drawOval(x, y, 2*radius, 2*radius); } } public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource() == j1) { x -= 20; repaint(); } else if(e.getSource() == j2){ x += 20; repaint(); }else if(e.getSource() == j3){ y -= 20; repaint(); }else if(e.getSource() == j4){ y += 20; repaint(); } } }
Test_16.java
相关文章推荐
- 设计模式:单件模式
- sqlite3 解决并发读写冲突的问题
- 面向对象编程的设计思想
- struts2的OGNL
- ansible 简单入门与使用
- 通过mapping.txt解析混淆apk的出错信息
- 递归求解N皇后
- 白话scala系列二 scala入门的几个基本知识
- redis源码安装
- java-String中的 intern()
- 开源库分享__通用数字分隔控件(NumberSeparateEditText)
- 文件句柄
- lua 小知识
- 【VS开发】【图像处理】双边滤波器bilateral filter
- hadoop异常 error in shuffle in fetcher
- 利用post-commit自动化持续部署Jexus站点
- RS-232, RS-422, RS-485 Serial Communication General Concepts(转载)
- 自建pod库
- [2016/07/02] LeetCode / Java - Day 10 -
- 使用volley上传图片,一个参数多张图、多张图片多张图