真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java畫(huà)圖代碼實(shí)現(xiàn) java編寫(xiě)畫(huà)圖程序

怎么用java代碼模擬一張圖片

用java代碼模擬一張圖片可以這樣操作:1.創(chuàng)建BufferedImage類

創(chuàng)新互聯(lián)專注于樂(lè)業(yè)企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),商城開(kāi)發(fā)。樂(lè)業(yè)網(wǎng)站建設(shè)公司,為樂(lè)業(yè)等地區(qū)提供建站服務(wù)。全流程按需求定制制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

2.根據(jù)BufferedImage類得到一個(gè)Graphics2D對(duì)象

3.根據(jù)Graphics2D對(duì)象進(jìn)行邏輯操作

4.處理繪圖

5.將繪制好的圖片寫(xiě)入到圖片

如何用Java編寫(xiě)一個(gè)繪制圖形的小程序?

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import javax.swing.*;

//不規(guī)則圖形的繪制

public class IrregularShapeDemo extends JFrame {

GeneralPath gPath= new GeneralPath(); //GeneralPath對(duì)象實(shí)例

Point aPoint;

//構(gòu)造函數(shù)

public IrregularShapeDemo() {

super("不規(guī)則圖形的繪制"); //調(diào)用父類構(gòu)造函數(shù)

enableEvents(AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK); //允許事件

setSize(300, 200); //設(shè)置窗口尺寸

setVisible(true); //設(shè)置窗口可視

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //關(guān)閉窗口時(shí)退出程序

}

public void paint(Graphics g) { //重載窗口組件的paint()方法

Graphics2D g2D = (Graphics2D)g;//獲取圖形環(huán)境

g2D.draw(gPath); //繪制路徑

}

public static void main(String[] args) {

new IrregularShapeDemo();

}

protected void processMouseEvent(MouseEvent e) { //鼠標(biāo)事件處理

if(e.getID() == MouseEvent.MOUSE_PRESSED) {

aPoint = e.getPoint(); //得到當(dāng)前鼠標(biāo)點(diǎn)

gPath = new GeneralPath(); //重新實(shí)例化GeneralPath對(duì)象

gPath.moveTo(aPoint.x,aPoint.y); //設(shè)置路徑點(diǎn)

}

}

protected void processMouseMotionEvent(MouseEvent e) { //鼠標(biāo)運(yùn)動(dòng)事件處理

if(e.getID() == MouseEvent.MOUSE_DRAGGED) {

aPoint = e.getPoint(); //得到當(dāng)前鼠標(biāo)點(diǎn)

gPath.lineTo(aPoint.x, aPoint.y); //設(shè)置路徑

gPath.moveTo(aPoint.x, aPoint.y);

repaint(); //重繪組件

}

}

}

用java編寫(xiě)一個(gè)簡(jiǎn)單的畫(huà)圖程序。不用復(fù)雜

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import javax.swing.*;

//不規(guī)則圖形的繪制

public class IrregularShapeDemo extends JFrame {

GeneralPath gPath= new GeneralPath(); //GeneralPath對(duì)象實(shí)例

Point aPoint;

//構(gòu)造函數(shù)

public IrregularShapeDemo() {

super("不規(guī)則圖形的繪制"); //調(diào)用父類構(gòu)造函數(shù)

enableEvents(AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK); //允許事件

setSize(300, 200); //設(shè)置窗口尺寸

setVisible(true); //設(shè)置窗口可視

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //關(guān)閉窗口時(shí)退出程序

}

public void paint(Graphics g) { //重載窗口組件的paint()方法

Graphics2D g2D = (Graphics2D)g; //獲取圖形環(huán)境

g2D.draw(gPath); //繪制路徑

}

public static void main(String[] args) {

new IrregularShapeDemo();

}

protected void processMouseEvent(MouseEvent e) { //鼠標(biāo)事件處理

if(e.getID() == MouseEvent.MOUSE_PRESSED) {

aPoint = e.getPoint(); //得到當(dāng)前鼠標(biāo)點(diǎn)

gPath = new GeneralPath(); //重新實(shí)例化GeneralPath對(duì)象

gPath.moveTo(aPoint.x,aPoint.y); //設(shè)置路徑點(diǎn)

}

}

protected void processMouseMotionEvent(MouseEvent e) { //鼠標(biāo)運(yùn)動(dòng)事件處理

if(e.getID() == MouseEvent.MOUSE_DRAGGED) {

aPoint = e.getPoint(); //得到當(dāng)前鼠標(biāo)點(diǎn)

gPath.lineTo(aPoint.x, aPoint.y); //設(shè)置路徑

gPath.moveTo(aPoint.x, aPoint.y);

repaint(); //重繪組件

}

}

}


網(wǎng)站標(biāo)題:java畫(huà)圖代碼實(shí)現(xiàn) java編寫(xiě)畫(huà)圖程序
轉(zhuǎn)載來(lái)源:http://weahome.cn/article/dohdidj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部