资源简介
1:采用单例模式设计;
2:应用双缓冲技术;
3:更改线段的颜色,宽度。
代码片段和文件信息
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.InternalframeEvent;
import javax.swing.event.InternalframeListener;
public class DrawPen implements ActionListener MouseListener
MouseMotionListener ItemListener
{
private static DrawPen instance=null;
Jframe frame;
MyCanvas cans;
JButton bt[] = new JButton[4];
JLabel lColor = new JLabel(“Color Setting“JLabel.RIGHT);
JLabel lLine = new JLabel(“Line Width“JLabel.RIGHT);
JLabel la = new JLabel();
JLabel lc = new JLabel();
JComboBox cob[] = new JComboBox[2];
String color[] = { “red“ “yellow“ “green“ “blue“ “black“ “white“};
String size[] = {“1““2““3““4““5““6““7““8““9“};
private Point dots[] = new Point[2048];
private int dot = 0;
private int LC = 0LD = 2flag = 0iStart_xiStart_yiLast_xiLast_yiHeightiWidth;
private int Screen_Width = 1024Screen_Height = 768;
private DrawPen()
{
Jframe frame = new Jframe(“JYGraphicsEX“);
frame.setSize(Screen_WidthScreen_Height);
Container con = frame.getContentPane(); //����
JPanel jp1 = new JPanel(new GridLayout(1 9 10 10));
String []btName = {“Line““Curve““Rectangle““Ellipse“};
for(int i = 0; i < bt.length; i++)
{
bt[i] = new JButton(btName[i]);
jp1.add(bt[i]);
bt[i].addActionListener(this);
}
for(int i = 0; i < cob.length; i++)
{
cob[i] = new JComboBox();
if(i == 0)
{
con.add(jp1“North“);
jp1.add(lColor);
for(int j = 0; j < 6; j++)
{
cob[i].addItem(color[j]);
jp1.add(cob[i]);
}
}else
{
for(int k = 0; k < 9; k++)
{
con.add(jp1“North“);
jp1.add(lLine);
cob[i].addItem(size[k]);
jp1.add(cob[i]);
}
}
cob[i].setBackground(Color.white);
cob[i].addItemListener(this);
}
jp1.add(la);
jp1.add(lc);
cans = new MyCanvas();
cans.setBackground(Color.BLACK);
cans.addMouseListener(this);
cans.addMouseMotionListener((MouseMotionListener)this);
con.add(cans);
frame.setVisible(true);
}
public void itemStateChanged(ItemEvent event)
{
if (event.getSource() == cob[0])
{
String str = (String) event.getItem();
for (int i = 0; i < 6; i++)
if (str == color[i])
LC = cob[0].getSelectedIndex(); //��ɫ����
}
if (event.getSource() == cob[1])
{
String str = (String)event.getItem();
for (int i = 0; i < 9; i++)
if (str == size[i])
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 301 2012-11-26 08:53 Jpen\.classpath
文件 380 2012-11-26 08:53 Jpen\.project
文件 629 2012-11-26 08:53 Jpen\.settings\org.eclipse.jdt.core.prefs
文件 9575 2012-11-28 15:32 Jpen\bin\DrawPen.class
文件 3185 2012-11-28 15:32 Jpen\bin\MyCanvas.class
文件 7136 2012-11-27 11:35 Jpen\src\DrawPen.java
文件 2678 2012-11-27 10:06 Jpen\src\MyCanvas.java
目录 0 2012-11-26 10:00 Jpen\.settings
目录 0 2012-11-28 15:32 Jpen\bin
目录 0 2012-11-26 10:00 Jpen\src
目录 0 2012-11-26 10:00 Jpen
----------- --------- ---------- ----- ----
23884 11
- 上一篇:ssm开发的erp系统源码
- 下一篇:经典JavaWeb在线通讯录
评论
共有 条评论