礼花(菜鸟程序)之一
来源:互联网 发布:最新网络水军价格 编辑:程序博客网 时间:2024/04/28 07:02
包,类层次:
测试类DropTest
包LiHua(含类:Position)
|
包Pen(含类:Drop)
*******************************************DropTest:********************************************************
import java.awt.*;
import java.awt.event.*;
import LiHua.Pen.*;
import LiHua.*;
class DropTest{
Frame frame;
Panel panel;
LiHua.Pen.Drop drop;
DropTest(){
System.out.println("Test in DropTest");
frame=new Frame();
panel=new Panel();
drop=new Drop();
panel.setBackground(Color.blue);
frame.add(panel);
frame.setSize(300,300);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
frame.dispose();
System.exit(0);
}
});
}
public static void main(String args[]){
DropTest test=new DropTest();
test.drop.setColor(Color.red);
test.drop.setSize(10);
test.drop.draw(new Position(200,150),test.panel.getGraphics());
}
}
***********************************************Position:***************************************************
package LiHua;
public class Position{
int x; //horizontal position
int y; //vertical position
//default position is on origin point
public Position(){
//ok System.out.println("test in Position"); // testing eeeee
x=0;
y=0;
}
//create it with given horizontal and vertical positons
public Position(int x,int y){
this.x=x;
this.y=y;
}
//create it with given center,radius and angle
public Position(Position center,int radius,int angle){
x=radius*(int)Math.cos(angle)+center.getX();
y=radius*(int)Math.sin(angle)+center.getY();
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public void setX(int x){
this.x=x;
}
public void setY(int y){
this.y=y;
}
*********************************************Drop:*******************************************************
/********************************************************
* A full filled circle
* which can be set with diferent colors and sizes
********************************************************/
package LiHua.Pen;
import java.awt.*;
import LiHua.*;
public class Drop{
int size; //the diameter of he Drop
Color color;
//if arguments are not given, the crytic diameter and color will be 5 and red
public Drop(){
size=5;
color=new Color(255,0,0);
}
public Drop(int size){
this.size=size;
color=new Color(255,0,0);
}
public Drop(Color color){
size=5;
this.color=color;
}
public Drop(int size,Color color){
this.size=size;
this.color=color;
}
//draw the filled circle with the setted diameter and color
public void draw(LiHua.Position position,Graphics g){
System.out.println("Test in Drop.draw()");
g.setColor(color);
g.fillOval(position.getX(),position.getY(),size,size);
}
public void draw(Graphics g,LiHua.Position position){
g.setColor(color);
g.fillOval(position.getX(),position.getY(),size,size);
}
public String toString(){
return "Drop:/n/tsize="+size+"/n/tcolor="+color;
}
public void setColor(Color color){
this.color=color;
}
public void setSize(int size){
this.size=size;
}
}
***************************************Problemes:*****************************************************
现存问题:
把窗口最小化后,再复原,红色实心圆消失。
---------------------------------------------------------------------------------------
曾出现问题:
开始的DropTest用JFrame,JPanel,然后用JPanel panel.getGraphics()获得画笔作为Drop的画笔参数。测试发现圆点时而出现,时而不出现,有时在窗口打开瞬间闪烁以下就消失了。
后来我想到可能getGraphics()是java.awt.Component的l类方法,或许用java.awt.Panel可以解决,于是换用Panel,果然圆点随即出现的问题解决了,但是很奇怪:javax.swing.JPanel也是java.awt.Component的子类 呀!用它为什么却会出现问题呢?
- 礼花(菜鸟程序)之一
- 礼花
- 菜鸟初学技术篇(之一)
- 程序菜鸟
- EC2菜鸟入门日记之一(登陆与验货)
- 菜鸟Dotnet学习路之一
- 非常好的awt放礼花程序 需要好好的看看 鼠标点击就 放的
- 程序设计之一:布雷程序(C++)
- 微信小程序之一(开始构建)
- 小程序学习笔记之一(框架结构)
- 菜鸟学做多语言版程序
- 菜鸟写程序
- 程序菜鸟的反思
- 程序媛菜鸟start
- 菜鸟与程序猿
- 菜鸟程序猿日记
- 菜鸟学习Linux 之一 系统安装(XP+Linux or Vista+Linux)
- 菜鸟宝典 数码相机选购入门手册(之一)
- Linux命令详解 — time
- eclipse,J2EE入门学习心得
- 大学里最重要的七项学习
- 果然是ie7的bug阿!
- 用asp.net和c#做个简易的Blog
- 礼花(菜鸟程序)之一
- [流行偶像]分析王菲唱腔的精辟文字(转载)
- CFrameWnd - MSDN6翻译交流
- 我决定不再轻易读那些书
- 浅谈ACM ICPC的题目风格和近几年题目的发展(王颖)
- java中随机数产生的办法
- classpath相关
- 获得汉字字符串拼音首字母 C#版
- c#取得汉字的拼音的首字母