滑鼠畫圖編程
⑴ Windows編程中如何用滑鼠畫多邊形
1.多邊形數據結構可以用鏈表
2.滑鼠左鍵事件添加節點到多邊形鏈表,啟動繪制多邊形
3.滑鼠移動事件,先擦除先前畫的(xor)最後一點與滑鼠點和第一點與滑鼠點之間的連線再畫上當前滑鼠點與第一最後一點連線,記錄滑鼠坐標點。
4.滑鼠右鍵事件響應擦除最後一點與倒數第二點,
以及最後一點與滑鼠點之間的連線,從多邊形坐標點中移出最後一點,啟動多邊形繪制
5.左鍵雙擊事件,當前滑鼠點加入多邊形鏈表,結束滑鼠繪制事件的響應多邊形鏈表數據處理保存繪制。
⑵ 做一個用滑鼠繪圖的java程序
寫了一個最基本的,可以照了代碼改復雜,功能都實現沒有問題。
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class DrawImage extends JFrame{
 
 private Container c = null;
 private JButton lineButton = null,
     rectangleButton = null,
     ovalButton = null,
     colorChooser=null,
     clearButton = null;
 private JTextField textField = null;
 
 private static int DRAW_LINE=0,
             DRAW_RECTANGLE=1,
             DRAW_OVAL=2,
             CLEAR=3;
 private int drawMode = DRAW_RECTANGLE;
 private int lineWidth = 5;
 private Color color = Color.RED;
 private JPanel drawPane,p=null;
 private DrawImage frame = null;
 
 private ActionListener buttonListener=null;
 private MouseListener mouseListener = null;
 
 private Point lp=new Point(-1,-1),    //滑鼠落下的點
     cp=new Point(-1,-1);   //滑鼠拖拽的點
 
 public DrawImage(){
  frame = this;
  initListener();
  initFrame();
 }
 
 public void initListener(){
  buttonListener = new ActionListener(){
   public void actionPerformed(ActionEvent e) {
    String str = ((JButton)e.getSource()).getText();
    if(str.compareTo("畫線")==0){
     drawMode = DRAW_LINE;
    }else if(str.compareTo("方形")==0){
     drawMode = DRAW_RECTANGLE;
    }else if(str.compareTo("畫圓")==0){
     drawMode = DRAW_OVAL;
    }else if(str.compareTo("擦除")==0){
     drawMode = CLEAR;
    }else if(str.compareTo("顏色")==0){
     color = JColorChooser.showDialog(frame, "取色板",color);
     colorChooser.setBackground(color);
    }
   }
   
  };
  
  mouseListener = new MouseListener(){
   public void mouseClicked(MouseEvent e) {
    
   }
   public void mouseEntered(MouseEvent e) {
}
   public void mouseExited(MouseEvent e) {
    
   }
   public void mousePressed(MouseEvent e) {
    lp = e.getPoint();
    
   }
   public void mouseReleased(MouseEvent e) {
    cp = e.getPoint();
    drawPane.repaint();
   }
   
  };
 }
 
 public void initFrame(){
  c=this.getContentPane();
  lineButton = new JButton("畫線");
  rectangleButton = new JButton("方形");
  ovalButton = new JButton("畫圓");
  clearButton = new JButton("擦除");
  colorChooser = new JButton("顏色");
  colorChooser.setBackground(color);
  textField = new JTextField(5);
  drawPane = new JPanel(){
   public void paint(Graphics g){
    g.setColor(color);
    if(drawMode==DRAW_LINE){
     g.drawLine(lp.x,lp.y, cp.x, cp.y);
    }else if(drawMode==DRAW_RECTANGLE){
     g.drawRect(lp.x, lp.y, Math.abs(lp.x-cp.x), Math.abs(lp.y-cp.y));
    }else if(drawMode==DRAW_OVAL){
     g.drawOval(lp.x, lp.y, Math.abs(lp.x-cp.x), Math.abs(lp.y-cp.y));
    }else if(drawMode==CLEAR){
     g.clearRect(lp.x, lp.y, Math.abs(lp.x-cp.x), Math.abs(lp.y-cp.y));
    }
   }
  };
  p = new JPanel();
  p.setPreferredSize(new Dimension(100,800));
  p.setLayout(new FlowLayout(FlowLayout.LEADING));
  p.add(lineButton);
  p.add(rectangleButton);
  p.add(ovalButton);
  p.add(clearButton);
  p.add(colorChooser);
  p.add(textField);
  
  lineButton.addActionListener(buttonListener);
  rectangleButton.addActionListener(buttonListener);
  ovalButton.addActionListener(buttonListener);
  colorChooser.addActionListener(buttonListener);
  clearButton.addActionListener(buttonListener);
  drawPane.addMouseListener(mouseListener);
  drawPane.setBorder(BorderFactory.createLineBorder(Color.red,3));
  c.add(p,BorderLayout.WEST);
  c.add(drawPane,BorderLayout.CENTER);
 }
 
 public static void main(String[] args){
  DrawImage frame = new DrawImage();
  frame.setVisible(true);
  frame.setSize(600,600);
  frame.setLocationRelativeTo(null);
  frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
 }
 
}
⑶ java 滑鼠畫圖
上學的時候寫過,不過不在公司的電腦裡面。呵呵,回去想到了給你……
package guitest.myboard;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
//the point 
//impress the info of one point,the x and y
class OnePoint implements Serializable {
 int x;
 int y;
 int tool;
 Color c;
 int border;
 
 public OnePoint(int x,int y,int tool,Color cc,int border){
  this.x=x;
  this.y=y;
  this.tool=tool;
  this.c=cc;
  this.border=border;
 }
}
class DrawingBoard extends Frame implements MouseListener,ItemListener,ActionListener,MouseMotionListener{
 
 Button pen;
 Button line ;
 Button ellipse ;
 Button rect ;
 Button clear ;
 Button colorboard ; 
 Button storebutton;
 Button openbutton;
 
 Choice sizechoice ;
 Choice colorchoice ;
 
 Label pensize;
 Label pencolor;
 Panel panel ;
 
 FileDialog  storefile;
 FileDialog  openfile;
 
 FileInputStream filein;
 FileOutputStream fileout;
 ObjectInputStream objectin;
 ObjectOutputStream objectout;
 
 int flagtool=0;
 Color flagcolor;
 int border;
 BasicStroke size;
 
 OnePoint p1,p2;
 Vector<OnePoint> points=new Vector<OnePoint>();
 
 public DrawingBoard(){
  pen=new Button("畫筆");
  line=new Button("直線");
  ellipse=new Button("圓");
  rect=new Button("矩形");
  clear=new Button("清除");
  colorboard=new Button("調色板");
  storebutton=new Button("存儲文件");
  openbutton=new Button("打開文件");
  
  pensize=new Label("畫筆大小");
  pencolor=new Label("畫筆顏色");
  
  storefile=new FileDialog(this,"存儲文件",FileDialog.SAVE);
  storefile.setVisible(false);
  storefile.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    storefile.setVisible(false);
   }
  });
  openfile=new FileDialog(this,"打開文件",FileDialog.LOAD);
  openfile.setVisible(false);
  openfile.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    openfile.setVisible(false);
   }
  });
  
  sizechoice=new Choice();
  sizechoice.add("1");
  sizechoice.add("2");
  sizechoice.add("4");
  sizechoice.add("6");
  sizechoice.add("8");
  sizechoice.addItemListener(this);
  
  colorchoice=new Choice();
  colorchoice.add("black");
  colorchoice.add("red");
  colorchoice.add("blue");
  colorchoice.add("green");
  colorchoice.addItemListener(this);
  
  pen.addActionListener(this);
  line.addActionListener(this);
  ellipse.addActionListener(this);
  rect.addActionListener(this);
  clear.addActionListener(this);
  colorboard.addActionListener(this);
  storebutton.addActionListener(this);
  openbutton.addActionListener(this);
  
  panel=new Panel(); 
  
  panel.add(storebutton);
  panel.add(openbutton);
  
  panel.add(pen);
  panel.add(line);
  panel.add(ellipse);
  panel.add(rect);
  panel.add(clear);
  
  panel.add(sizechoice);
  panel.add(pensize);
  
  panel.add(colorchoice);
  panel.add(pencolor);
  panel.add(colorboard);
  
  add(panel,BorderLayout.NORTH);
  setBounds(100,100,700,600);
  setVisible(true);
  
  addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    System.exit(0);
   }
  });
  
  /**
   * 添加滑鼠事件的監聽器,否則,滑鼠的移動和點擊都將無法識別!
   * */
  addMouseListener(this);
  addMouseMotionListener(this);
 }
 
 public void paint(Graphics g){
  
  Graphics2D g2d=(Graphics2D)g;
  if(flagtool==2){                    //qing chu
   g.clearRect(0,0,getSize().width,getSize().height);
  }
  for(int i=0;i<points.size()-1;i++){
   p1=(OnePoint)points.elementAt(i);
   p2=(OnePoint)points.elementAt(i+1);
   
   g2d.setColor(p1.c); //////////////需要使用Graphics2D從Graphics類中繼承下來的方法 setColor()設置當前的顏色
   size=new BasicStroke(p1.border,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
   g2d.setStroke(size);
   
   if(p1.tool==p2.tool){
   switch(p1.tool){
   case 0:  
    Line2D.Double line1=new Line2D.Double(p1.x,p1.y,p2.x,p2.y);
    g2d.draw(line1);
    break;
   case 1:
    Line2D.Double line2=new Line2D.Double(p1.x,p1.y,p2.x,p2.y);
    g2d.draw(line2);
    break;
   case 3:
    Ellipse2D.Double ellipse=new Ellipse2D.Double(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
    g2d.draw(ellipse);
    break;
   case 4:
    Rectangle2D.Double rect=new Rectangle2D.Double(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
    g2d.draw(rect);
    break;
   default:
   }
    }
  } 
 }
 
 public void mouseClicked(MouseEvent e) {}
 public void mouseEntered(MouseEvent e) {}
 public void mouseExited(MouseEvent e) {}
 public void mousePressed(MouseEvent e) { //滑鼠點下時候,將當前的點信息記錄
  
  OnePoint pp1=new OnePoint(e.getX(),e.getY(),flagtool,flagcolor,border);
  points.addElement(pp1);
  //repaint();
 }
 public void mouseReleased(MouseEvent e) {//滑鼠松開時候,如果是畫筆,則當前截斷,是其餘狀態記下一枚點信息
  if(flagtool==0){
   points.addElement(new OnePoint(-1,-1,22,flagcolor,border));
  }
  else{
   OnePoint pp2=new OnePoint(e.getX(),e.getY(),flagtool,flagcolor,border);
   points.addElement(pp2);
   points.add(new OnePoint(-1,-1,22,flagcolor,border));
  }
  repaint();
 }
 public void itemStateChanged(ItemEvent e) {
  if(e.getSource()==colorchoice){
   String selected=colorchoice.getSelectedItem();
   if(selected=="black"){
    flagcolor=new Color(0,0,0);
   }
   else if(selected=="red"){
    flagcolor=new Color(255,0,0);
   }
   else if(selected=="blue"){
    flagcolor=new Color(0,0,255);
   }
   else if(selected=="green"){
    flagcolor=new Color(0,255,0);
   }
  }
  else if(e.getSource()==sizechoice){
   String selected=sizechoice.getSelectedItem();
   if (selected=="1"){
    border=1;
   }
   else if(selected=="2"){
    border=2*2;
   }
   else if(selected=="4"){
    border=4*2;
   }
   else if(selected=="6"){
    border=6*2;
   }
   else if(selected=="8"){
    border=8*2;
   }
  }
  
 }
 public void update(Graphics g) {   //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  paint(g);
 }
 public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if(e.getSource()==pen){
   flagtool=0;
  }
  else if(e.getSource()==line){
   flagtool=1;
  }
  else if(e.getSource()==clear){
   flagtool=2;
   points.removeAllElements();
   repaint();      //此語要有,否則今生無法刪除!
  }
  else if(e.getSource()==ellipse){
   flagtool=3;
  }
  else if(e.getSource()==rect){
   flagtool=4;
  }
  else if(e.getSource()==colorboard){
   /*
    * 使用 javax.swing.×包中的 JColorChooser 類的靜態方法showDialog(Component component,String title,Color color ),
    * 該方法的參數,component是當前顯示對話框的父框架,color是設置調色板初始的被選顏色
    * 
    * 該方法返回被選的顏色,類型為Color
    * */
   Color color=JColorChooser.showDialog(this, "調色板",flagcolor);
   flagcolor=color;
  }
  else if(e.getSource()==openbutton){
   openfile.setVisible(true);
   if(openfile.getFile()!=null){   
    int temp=flagtool;
    flagtool=2;
    repaint();
    try{
     points.removeAllElements();
     File file=new File(openfile.getDirectory(),openfile.getFile());
     filein=new FileInputStream(file);
     objectin=new ObjectInputStream(filein);
     points=(Vector)objectin.readObject();
     objectin.close();
     filein.close();
     flagtool=temp;
     repaint();
    }
    catch(Exception ee){
     System.out.println(ee.toString());
    }
   }
  }
  else if(e.getSource()==storebutton){
   storefile.setVisible(true);
   if(storefile.getFile()!=null){    
    try {
     File file=new File(storefile.getDirectory(),storefile.getFile());
     fileout=new FileOutputStream(file);
     objectout=new ObjectOutputStream(fileout);
     objectout.writeObject(points);
     objectout.close();
     fileout.close();
     repaint();
    }
    catch (FileNotFoundException e1) {
     System.out.println(e1.toString());
     e1.printStackTrace();
    } catch (IOException ee) {
     System.out.println(ee.toString());
     ee.printStackTrace();
    }
   }
  }
 }
 public void mouseDragged(MouseEvent e) {//滑鼠拖動時候,//當且僅當 flagtool==0,或者表示為橡皮的時候
           //才將拖動過程中涉及到的點全部記錄下來,並且調用repain()方法,重畫當前
  // TODO Auto-generated method stub
  if(flagtool==0){
   OnePoint pp3=new OnePoint(e.getX(),e.getY(),flagtool,flagcolor,border);
   points.addElement(pp3);
   repaint();
  }
 }
 public void mouseMoved(MouseEvent e) {
  // TODO Auto-generated method stub  
 }
}
public class PaintBoard{
 public static void main(String[] args){
  DrawingBoard oneBorder=new DrawingBoard();
 }
}
⑷ CNC畫圖編程用什麼滑鼠好
羅技。CNC畫圖編程對滑鼠的要求是最低的,基本上沒有要求。計算機輔助設計,本身就是有彌補手工制圖的缺點,以及對手工的依賴性的作用在裡面。推薦買個普通能用的就行,建議無線滑鼠,因為方便。沒必要買游戲滑鼠,貴且不說,為了高DPI和高刷新率,更加費電,電池用不到多久。所以羅技滑鼠就行,便宜也好用。
⑸ 【QT畫圖】怎麼實現用滑鼠畫圖功能
獲取滑鼠點擊的位置然後畫一個點,點的粗細可以自己定,這樣不斷的畫點,所有點連起來就是連續的線了
⑹ 如何用C語言編寫一個圖形編輯器並支持滑鼠和畫圖功能
直接用C語言實現的話很麻煩     在這我說一句要實現一個圖形系統是件困難的是一種語言是不夠的要結合多種語言  比如C    C++   匯編    matlab
等等!!!還設計很多理論知識   所以比較復雜     你可以用VC++編寫一個簡單的差不多和windows子帶的差不多 VC++環境有很多圖形函數可以幫助你很好的實現自己的目的....程序設計的道路是漫長的.....要時刻動手動腦.....編程是枯燥的但是要寫好一個程序回頭看會有成就感的...祝你成功!!
⑺ 滑鼠如何進行編程
在java.awt.*包下面有一個Robot類,可以生成輸入事件,例如,Robot.mouseMove 將移動滑鼠游標 
這個類除了模擬滑鼠鍵盤操作以外,還可以用來截取屏幕,只演示一下怎麼模擬滑鼠鍵盤操作,具體api參考javadoc。這個演示完成了彈出QQ和移動窗口的功能。代碼如下: 
import java.awt.AWTException; 
import java.awt.Robot; 
import java.awt.event.KeyEvent; 
/** 
* @author bean 
* 
*/ 
public class RobotDemo { 
private Robot robot = null; 
public RobotDemo() { 
try { 
robot = new Robot(); 
} catch (AWTException e) { 
e.printStackTrace(); 
} 
} 
/** 可以彈出QQ */ 
public void keyBoardDemo() { 
robot.keyPress(KeyEvent.VK_ALT); 
robot.keyPress(KeyEvent.VK_CONTROL); 
robot.keyPress(KeyEvent.VK_Z); 
robot.keyRelease(KeyEvent.VK_Z); 
robot.keyRelease(KeyEvent.VK_CONTROL); 
robot.keyRelease(KeyEvent.VK_ALT); 
} 
/** 前提是有個最大化的窗口,功能是移動到標題欄,然後拖拽到600,600的位置*/ 
public void mouseDemo(){ 
robot.mouseMove(80, 10); 
robot.mousePress(KeyEvent.BUTTON1_MASK); 
try {
⑻ 怎樣用matlab編程用滑鼠畫直線
我以為你想知道的是以下幾個問題,
1、畫直線,在繪圖界面調出繪圖編輯工具欄,如下所示:

之後可畫直線
2、獲得曲線上點,使用ginput命令
如下命令
t=-10:0.1:10;
Y=sin(t).^2.*exp(-0.1*t)-0.5*abs(t);
clf,
plot(t,Y,'r')
hold on
plot(t,zeros(size(t)),'k')
xlabel('t'),ylabel('y(t)')
hold off
zoom on
[tt,yy]=ginput(10);
zoom off;
tt
yy
3、曲線擬合
x=1:100;
y=randn(1,100);
plot(x,y,'*');%散點圖
p = polyfit(x,y,1);
hold on
a=p(1)
b=p(2)
z=a*x+b;
plot(x,z)%擬合曲線
hold off
⑼ 怎樣用滑鼠繪畫啊
使用下載的繪圖軟體例如SAI、PS(Photoshop)之類的,或者是網頁里本身帶的(例如百田塗鴉板、4399塗鴉板之類的,但相比之前兩種還是專業性差了一些,網速不好慎用,很容易卡住,我自己也曾經碰上過明明保存了再打開一塌糊塗的境地。所以建議還是在網上下個繪圖軟體,個人喜歡SAI,防抖)
滑鼠繪畫其實很磨時間的。相對於使用板子(事實上板子線稿也很麻煩,不過打草稿簡單很多)會難很多。主要就是要不停的修改,橡皮擦和鉛筆反復修稿,最終呈現出干凈的線稿。至於上色就相對簡單一些,至少有前人帶領,並且和板繪差不多,可以去SAI吧、PS吧之類的地方轉一轉,熟悉一下軟體的各種性能(其實我也在摸索中),也可以去報個班 。
有耐心、有毅力、有充分的藝術修養影響一幅畫的好壞,多多練習才是正道。
