当前位置:首页 > 代码 > 正文

图java代码(java程序图)

admin 发布:2022-12-19 20:59 137


本篇文章给大家谈谈图java代码,以及java程序图对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java载入图片只载入图片的一部分,求代码

import java.awt.Graphics;

import java.awt.Image;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class TestFrame extends JFrame {

public TestFrame() {

MyJPanel mp = new MyJPanel();

add(mp);

setTitle("画图");

setDefaultCloseOperation(EXIT_ON_CLOSE);

setBounds(300, 200, 300, 300);

setVisible(true);

}

public static void main(String[] args) {

new TestFrame();

}

class MyJPanel extends JPanel {

public void paint(Graphics g) {

super.paint(g);

Image img = new ImageIcon("C:\\Users\\gyona\\Desktop\\12.jpg").getImage();

g.drawImage(img, 0, 0, 100, 100, 100, 100, 200, 200, this);

//下面2组参数,确定画在JPanel的什么位置上

//0, 0//左上顶点

//100,100//确定画在JPanel时候的长和宽

//下面2组参数,用于决定选取图片的什么区域

//100,100 //选取图片的左顶点

//200,200 右下顶点

}

}

}

效果

如何用java代码获取 这个网页上的图片

你也没说是要把图片下载下来还是什么的

这里我实现的是将图片下载到电脑

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.net.HttpURLConnection;

import java.net.MalformedURLException;

import java.net.URL;

public class DownLoad {

public static void main(String[] args) {

File dstFile = new File("E:/test/test/test.jpg");

try {

URL url = new URL("");

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

InputStream is = conn.getInputStream();

saveFile(is, dstFile);

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

public static void saveFile(InputStream is,File dstFile){

FileOutputStream fos = null;

File parentFile = dstFile.getParentFile();

if(!parentFile.exists()){

parentFile.mkdirs();

}

try {

fos = new FileOutputStream(dstFile);

byte[] buff = new byte[1024 * 4];

int len;

while((len = is.read(buff)) != -1){

fos.write(buff, 0, len);

}

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}finally{

try{

if(is != null){

is.close();

}

if(fos != null){

fos.close();

}

}catch(IOException e){

e.printStackTrace();

}

}

}

}

解析下这个生成图片的Java代码

1.调用"images"文件夹里的文件放在ImageIcon里显示2.在windows下面显示正常Java在图形处理时调用了本地的图形处理库。在利用Java作图形处理(比如:图片缩放,图片签名,生成报表)时,如果运行在windows上不会出问题。如果将程序移植到Linux/Unix上的时候有可能出现图形不能显示的错误。3.提示信息:"Can'tconnecttoX11windowserver"这是由于Linux的图形处理需要一个XServer服务器。(关于Linux的图形处理模式参考Tomcat的修改如下:打开%Tomcat_home%/bin/catalina.sh文件在文件的86%处,启动Tomcat的脚本中加上:-Djava.awt.headless=true/参考:"$_RUNJAVA"$JAVA_OPTS$CATALINA_OPTS/-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS"-classpath"$CLASSPATH"/-Dcatalina.base="$CATALINA_BASE"/-Dcatalina.home="$CATALINA_HOME"/-Djava.io.tmpdir="$CATALINA_TMPDIR"/-Djava.awt.headless=true/org.apache.catalina.startup.Bootstrap"$@"start/"$CATALINA_BASE"/logs/catalina.out21if[!-z"$CATALINA_PID"];thenecho$!$CATALINA_PIDfifielif["$1"="stop"];then保存后,重新启动就可以处理图形了。

根据UML图,写出Java程序的代码

public interface ILeanable{

    public void stuy();

}

public interface ITeacher{

    public void teach();

}

public class Person{

    String name;

}

public class Student extends Person implements ILeanable{

    int age;

    String address;

}

public class Teacher extends Person implements ITeacher{

    String major;

    int age;

}

通过文字搜索图片 java代码实现及说明

import ja.io.*;

//获取文件夹内容

public class getthing

{

public static void main(String[] args) throws Exception

{

System.out.println(welstr);

listFile(new File("e:\\aa")); //想要搜索的路径

}

public static void listFile(File file) throws Exception

{

if(file.isFile())

{

//输出的是完整的文件夹内文件的路径

System.out.println("File :"+file.getAbsolutePath());

//01.jpg就是你要找的图片

if (file.getAbsolutePath().endsWith("01.jpg"))

System.out.println("有搜索的图片");

}

else

{

System.out.println("Dir :"+file.getAbsolutePath());

File[] files =file.listFiles();

for(int i=0;ifiles.length;i++)

{

listFile(files[i]);

System.out.println("回车");

}

}

}

}

1 首先确定你要搜索的目录

2 要搜索的关键字 如“花”

3 只搜索图片类型 .jpg .gif .png .bmp之类的

4 在文本框里获得搜索的关键字

5 取得要搜索目录下的所有图片类型的名字

6 用关键字和取得的文件名一一进行对比

7 若有关键字 记录该图片的名字

8 若都没关键字 表示无该名字的图片

9 空白区域你可以用一个窗体来表示

10 把搜索到的图片都显示在这个窗体。

按照下列UML图,用java实现代码?

Point2D.java

/**

* Title: Point2D.javabr

* Description:

*

* @author 王凯芳

* @date 2020年3月5日 下午7:09:35

* @version 1.0

*/

public class Point2D {

protected float x;

protected float y;

public Point2D() {

super();

}

public Point2D(float x, float y) {

super();

this.x = x;

this.y = y;

}

public float getX() {

return x;

}

public void setX(float x) {

this.x = x;

}

public float getY() {

return y;

}

public void setY(float y) {

this.y = y;

}

public float[] getXY() {

return new float[] { x, y };

}

public void setXY(float x, float y) {

this.x = x;

this.y = y;

}

@Override

public String toString() {

return "(" + x + "," + y + ")";

}

}

Point3D.java

/**

* Title: Point3D.javabr

* Description:

*

* @author 王凯芳

* @date 2020年3月5日 下午7:09:35

* @version 1.0

*/

public class Point3D extends Point2D {

private float z;

public Point3D() {

super();

}

public Point3D(float x, float y, float z) {

super();

this.x = x;

this.y = y;

this.z = z;

}

public float getZ() {

return z;

}

public void setZ(float z) {

this.z = z;

}

public float[] getXYZ() {

return new float[] { x, y, z };

}

public void setXYZ(float x, float y, float z) {

this.x = x;

this.y = y;

this.z = z;

}

@Override

public String toString() {

return "(" + x + "," + y + "," + z + ")";

}

}

图java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java程序图、图java代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/23880.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载