尚未完成的臭作(1),欢迎有兴趣和耐心的朋友进来看看
如果你有耐心就请看看我的代码。直接拷贝编译就可运行。我将不胜感激!!
代码还很混乱,结构也很不合理。功能还很不完善。我的想法是把它做成一个象样的程序。欢迎有兴趣的朋友和我一起做阿。用到的知识点都很简单,Swing,图像处理和线程。也希望有牛人帮我做一下系统分析,是结构更合理,代码显得更专业。
欢迎你提任何意见。
可以直接给我发短信或发邮件
tomcatlee2003@yahoo.com.cn
//显示器测试程序,测试显示器的色彩,失真,分辨率等。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TVTest extends JFrame
{
static final int RGB=0;//彩卡
static final int GRAY=1;//灰阶
static final int GRID=2;//网格
static final int MOTIVATION=3;//动画
ImageIcon[] images=null;//标签上的图像
JPanel rgb,gray,grid,motivation;
JLabel rgblabel,graylabel,gridlabel,motilabel;
public CHTVTest(String title){
super(title);
rgb=new JPanel();
gray=new JPanel();
grid=new JPanel();
motivation=new JPanel();
images=new ImageIcon[4];
for(int i=0;i<4;i++)
{
images[i]=new ImageIcon(i+".jpg");
}
Container container=getContentPane();
container.setLayout(new FlowLayout());
JLabel rgblabel=new JLabel(images[RGB],JLabel.CENTER);
JLabel graylabel=new JLabel(images[GRAY],JLabel.CENTER);
JLabel gridlabel=new JLabel(images[GRID],JLabel.CENTER);
JLabel motilabel=new JLabel(images[MOTIVATION],JLabel.CENTER);
rgblabel.addMouseListener(new MyListener(RGB));
graylabel.addMouseListener(new MyListener(GRAY));
gridlabel.addMouseListener(new MyListener(GRID));
motilabel.addMouseListener(new MyListener(MOTIVATION));
rgb.add(rgblabel);
gray.add(graylabel);
grid.add(gridlabel);
motivation.add(motilabel);
container.add(rgb);
container.add(gray);
container.add(grid);
container.add(motivation);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we)
{
System.exit(0);
}});
setSize(300,300);
setLocation(100,100);
setVisible(true);
}
public static void main(String args[])
{
new TVTest("显示器测试卡");
}
}
class FullScreenFrame extends JFrame implements MouseListener
{
int pattern=-1;
MyCanvas canvas=null;
Graphics canvasgraph;
Dimension screensize;
public void init()
{
canvas=new MyCanvas(pattern,this);
screensize=Toolkit.getDefaultToolkit().getScreenSize();
}
public FullScreenFrame(int pattern)
{
super();
this.pattern=pattern;
init();
setUndecorated(true);
getContentPane().add(canvas);
addMouseListener(this);
pack();
setSize(screensize);
setVisible(true);
canvas.init();
}
public void mouseClicked(MouseEvent me) {}
public void mouseEntered(MouseEvent me) {}
public void mouseExited(MouseEvent me) {}
public void mousePressed(MouseEvent me)
{
// new FullScreenFrame();
}
public void mouseReleased(MouseEvent me)
{}
}
class MyCanvas extends Canvas implements MouseListener
{
public Draw draw;
private Color colour = Color.black;
private Color bgColor = Color.black;
private Color fgColor=Color.black;
private int canvasWidth;
private int canvasHeight;
private int pattern=-1;
public JFrame jf=null;
Image bufferimage;
Graphics canvasGC,bufferGC;
//int pattern=-1;
public MyCanvas(int pattern,JFrame jf)
{
this.pattern=pattern;
addMouseListener(this);
this.jf=jf;
}
public void mouseClicked(MouseEvent me) {}
public void mouseEntered(MouseEvent me) {}
public void mouseExited(MouseEvent me) {}
public void mousePressed(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
if(me.getButton()==MouseEvent.BUTTON1)
{
clear(bufferGC,canvasWidth,canvasHeight);
drawFigure(bufferGC);
repaint();
}else{
draw.stop=true;
draw.thread=null;
jf.dispose();
}
}
public void paint(Graphics g)
{
g.drawImage(bufferimage,0,0,this);
}
public void update(Graphics g)
{
paint(g);
}
public void drawFigure(Graphics g)
{
draw.drawInPattern(g);
}
public void init()
{
Dimension d = getSize();
canvasWidth = d.width;
canvasHeight = d.height;
canvasGC = getGraphics();
bufferimage = createImage(canvasWidth,canvasHeight);
bufferGC = bufferimage.getGraphics();
draw=new Draw(pattern,canvasWidth,canvasHeight,bufferGC,this);
bgColor = getBackground();
fgColor = getForeground();
}
public void clear(Graphics g,int width,int height)
{
g.setColor(Color.black);
g.fillRect(0,0,width,height);
}
}
这里发言限长度,其余的代码请看
尚未完成的臭作(2),欢迎有兴趣和耐心的朋友进来看看
问题点数:0、回复次数:0Top




