日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java有画图的库吗_Java画图

發布時間:2025/3/19 java 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java有画图的库吗_Java画图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

//利用awt.Graphics畫圖

//Graph用于顯示所要畫的圖型

//Shape的子類定義可以圖形

//要改變圖形,可以利用Graphics類提供的方法實現

//要在同一窗口顯示更多圖形,通過重載paint()實現。

java" style="padding: 0.3em; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; color: rgb(51, 51, 51); border-radius: 4px; margin-top: 0px; margin-bottom: 1.5em; line-height: 1.5em; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.14902); overflow-y: auto; background-color: rgb(246, 246, 246);">

import java.awt.Graphics;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Graph extends JPanel {

/**

*

*/

private static final long serialVersionUID = 1L;

private Shape shape;

public Graph(Shape shp) {

super();

this.shape = shp;

}

@Override

public void paint(Graphics g) {

super.paint(g);

shape.draw(g);

}

public static void main(String[] args) {

// TODO Auto-generated method stub

JFrame frame = new JFrame();

frame.setTitle("Shape");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Rect rect = new Rect(10,10,100,100);

Graph grp = new Graph(rect);

frame.add(grp);

frame.setLocationRelativeTo(null);

frame.setSize(600,400);

frame.setVisible(true);

}

}

abstract class Shape{

public abstract void draw(Graphics g);

}

class Rect extends Shape{

private int x,y,sizeX,sizeY;

public Rect(int x,int y,int sizeX,int sizeY){

this.x = x;

this.y = y;

this.sizeX = sizeX;

this.sizeY = sizeY;

}

public void draw(Graphics g){

g.drawRect(x,y,sizeX,sizeY);

}

}

class Line extends Shape{

private int x,y,sizeX,sizeY;

public Line(int x,int y,int sizeX,int sizeY){

this.x = x;

this.y = y;

this.sizeX = sizeX;

this.sizeY = sizeY;

}

public void draw(Graphics g){

g.drawLine(x,y,sizeX,sizeY);

}

}

總結

以上是生活随笔為你收集整理的java有画图的库吗_Java画图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。