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