画圆操作

package demo1;

import java.awt.Graphics;
import javax.swing.*;
import javax.swing.JPanel; public class Demo2 extends JFrame {
Myframe mp; public static void main(String[] args) {
Demo2 demo = new Demo2();
} public Demo2() {
mp = new Myframe();
this.add(mp);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
} // Myframe定义的面板用于绘图
class Myframe extends JPanel {
public void paint(Graphics g) {
super.paint(g);
g.drawOval(100, 100, 30, 30);
}
}
package demo1;

import java.awt.Color;
//横着x 竖着y
import java.awt.Graphics;
import javax.swing.*;
import javax.swing.JPanel; public class Demo2 extends JFrame {
Myframe mp; public static void main(String[] args) {
Demo2 demo = new Demo2();
} public Demo2() {
mp = new Myframe();
this.add(mp);
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
} // Myframe定义的面板用于绘图
class Myframe extends JPanel {
public void paint(Graphics g) {
super.paint(g);
// 画圆
g.drawOval(100, 100, 30, 30);
// 直线
g.drawLine(80, 10, 40, 40);
// 矩形边框
g.drawRect(10, 10, 40, 60);
// 填充矩形
g.setColor(Color.blue);
g.fillRect(10, 10, 40, 60);
//
}
}

不晓得为何JPanel抓不到图片,

package demo1;

//横着x 竖着y
import java.awt.*; import javax.swing.*;
import javax.swing.JPanel; public class Demo2 extends JFrame {
Myframe mp; public static void main(String[] args) {
Demo2 demo = new Demo2();
} public Demo2() {
mp = new Myframe();
this.add(mp);
this.setSize(400, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
} // Myframe定义的面板用于绘图
class Myframe extends JPanel {
public void paint(Graphics g) {
super.paint(g);
// 画圆
// g.drawOval(100, 100, 30, 30); // // 直线
// g.drawLine(80, 10, 40, 40);
// // 矩形边框 // g.drawRect(10, 10, 40, 60);
// // 填充矩形
// g.setColor(Color.blue);
// g.fillRect(10, 10, 40, 60);
// //
Image im = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("E:/Java学习/tanke/src/image/hello.jpg"));
g.drawImage(im, 90, 90, 50, 30, this);
// 画出字体
// g.setColor(Color.RED);
// g.setFont(new Font("华文彩云",Font.BOLD,50));
// g.drawString("祖国万岁", 100, 100);
//
}
}

tanke1.0

package demo1;
/**
* 坦克游戏的1.0版
* @author Administrator
*/
import javax.swing.*;
import java.awt.*;
public class Tanke1 extends JFrame{
Mypanel mp; public static void main(String[] args) {
Tanke1 tank=new Tanke1();
}
public Tanke1(){
mp=new Mypanel();
this.add(mp);
this.setSize(400,300);
this.setVisible(true);
}
} //我的面板
class Mypanel extends JPanel{
Hero hero;
public Mypanel(){
hero=new Hero(10,10); }
//重写
public void paint(Graphics g){
super.paint(g);
//画出我的坦克
// * 1.画出左边的坦克
g.setColor(Color.blue);
g.fillRect(hero.getX(),hero.getY(),59,59); }
} //坦克类
class Tank{
//
int x=0;//横坐标
int y=0;
public Tank(int x,int y){
this.x=x;
this.y=y;
}
//自动获取内容
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
} }
//我的坦克
class Hero extends Tank{ public Hero(int x, int y) {
super(x, y);
} }

最新文章

  1. 响应式布局-Rem的用法
  2. Google Code Jam Round 1A 2015 解题报告
  3. 赫夫曼\哈夫曼\霍夫曼编码 (Huffman Tree)
  4. 《Haskell趣学指南 Learn You a Haskell for Great Good!》-代码实验
  5. nginx日志分析手机使用频次
  6. c语言中的二分法
  7. OpenERP 7.0 中文报表PDF乱码(WindowsXP)
  8. (step4.3.5)hdu 1501(Zipper——DFS)
  9. 【转】tkinter实现的文本编辑器
  10. hdu Joseph
  11. xshell配色Solarized Dark
  12. 基于SVM的鸢尾花数据集分类实现[使用Matlab]
  13. 【UML】NO.53.EBook.5.UML.1.013-【UML 大战需求分析】- 组合结构图(Composition Structure Diagram)
  14. MySQL 存储修改
  15. day30 hashlib模块
  16. XPATH的几个常用函数
  17. tf.concat, tf.stack和tf.unstack的用法
  18. js 原型链 prototype __proto__
  19. python3 数据库查询
  20. C 学习之大小端

热门文章

  1. 基于IPV6数据包的分析(GNS3)
  2. jdk安装 java环境配置
  3. 团队选题报告(bull beer)
  4. 进阶!基于CentOS7系统使用cobbler实现单台服务器批量自动化安装不同版本系统(week3_day5_part2)-技术流ken
  5. 展开隐形的翅膀,WPR003N补完篇
  6. C#中的CultureInfo类
  7. 从QA到工程能效团队
  8. 将Xml文件递归加载到TreeView中
  9. 算法题:实现一个IP白名单过滤器
  10. Python二级-----------程序冲刺4