Graphic
画圆操作
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);
} }
Graphic的更多相关文章
- FK JavaScript之:ArcGIS JavaScript添加Graphic,地图界面却不显示
使用ArcGIS JavaScript,往地图中添加几个Graphic,基本是与官网示例代码一致.绘制的图形一闪而过之后,就没了 核心代码如下: iniToolBar: function () { t ...
- Animating graphic objects in Windows Forms.
原文: Animating graphic objects in Windows Forms. http://bobpowell.net/animation.aspx 文件下载备份:http://fi ...
- Graphic geometry
Graphic有3个很重要的属性:geometry.symbol和attributes. •geometry属性定义的是一个几何对象,它是Graphic的基础,因为Graphic要表达的就是这个几何对 ...
- C# Graphic 绘制圆、三角形、椭圆、图片
在form和panel上可以绘制图形,线段,圆,文字,图形等等. 绘制代码必须放在OnPaint()函数里面,因为窗体刷新的时候,都会调用该函数,重新刷新所绘的图. 示例代码在Panel上绘制图形来简 ...
- Solution for Latex error: "Cannot determine size of graphic"
I'm trying to include graphics in my Latex-file, which I compiled with latex+dvipdf on OS X. Latex h ...
- 进阶:案例五: Dynamic 创建 Business Graphic
效果图: step: 无需节点无需UI 1.添加属性 2.代码: method WDDOMODIFYVIEW . DATA:lr_graph TYPE REF TO cl_wd_business_gr ...
- 与众不同 windows phone (17) - Graphic and Animation(画图和动画)
原文:与众不同 windows phone (17) - Graphic and Animation(画图和动画) [索引页][源码下载] 与众不同 windows phone (17) - Grap ...
- 使用Visifire+ArcGIS API for Silverlight实现Graphic信息的动态图表显示
原文:使用Visifire+ArcGIS API for Silverlight实现Graphic信息的动态图表显示 首先来看一看实现的效果: PS:原始的程序中更新曲线数据时添加了过渡的效果,具体可 ...
- typescript + echarts-for-react 制作渐变柱状图, 提示[ts] 类型“Graphic”上不存在属性“LinearGradient”
更新: 2019/03 无意间发现Graphic上已有 LinearGradient属性
- arcgis for js学习之Graphic类
arcgis for js学习之Graphic类 <title>Graphic类</title> <meta charset="utf-8" /> ...
随机推荐
- 经典排序算法 — C# 版(上)
提起排序,与我们的息息相关,平时开发的代码少不了排序. 经典的排序算法又非常多,我们怎么评价一个排序算法的好坏呢? 其实可以这样想,要细致的比较排序算法好坏,那我们就从多方面尽可能详细的对比 一.效率 ...
- 从壹开始前后端分离 [ vue + .netcore 补充教程 ] 二八║ Nuxt 基础:面向源码研究Nuxt.js
前言 哈喽大家周五好,又是一个开开心心的周五了,接下来就是三天小团圆啦,这里先祝大家节日快乐咯,希望都没有加班哈哈,今天公司发了月饼,嗯~时间来不及了,上周应该搞个活动抽中几个粉丝发月饼的,下次吧,这 ...
- MaterialCalendarDialog【Material样式的日历对话框】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 Material样式的日历对话框 前提条件:Activity界面必须继承FragmentActivity或者其子类(比如AppCom ...
- dotnet core开源博客系统XBlog介绍
XBlog是dotnet core平台下的个人博客开源系统,它只需要通过Copy的方式即可以部署到Linux和windows系统中:如果你有安全证书那只需要简单配置一下即可提供安全的Https服务.接 ...
- 值得一看的35个Redis常用问题总结
1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库 ...
- C# 切换中英文输入法
在界面输入时,有时需要限定输入法. 在不自定义正则表达式或者其它输入处理的情况下,切换中英文时与当前语言栏匹配,有以下的几种系统方案: InputLanguage方案 使用System.Windows ...
- 关于时间的那些事--PHP、JavaScript、MySQL操作时间
PHP篇 PHP中时间操作单位是秒 一.将时间戳转为普通日期格式 //当前时间戳 time(); //当前时间格式 date("Y-m-d H:i:s",time()); //昨天 ...
- Vmware安装CentOs7+gitlab(二)
在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开系统防火墙中的HTTP和SSH端口访问. 1.安装ssh和python sudo y ...
- java的设计模式 - 静态工厂方法
静态工厂方法,也不知道为何叫这个名字.其实也就是一个静态函数,可以替代构造函数用.大名鼎鼎的 guava 就大量使用这种模式,这是非常有用的模式. 比如是 Integer i = Integer.va ...
- js 格林威治时间转正常格式并兼容ios
function timeChange(time) { var date = time.substr(0, 10); //年月日 var hours = time.substring(11, 13); ...