「java显示图形」java中显示图片

博主:adminadmin 2022-11-30 23:21:06 77

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

本文目录一览:

JAVA 在屏幕上显示图形

import java.awt.Graphics;

import javax.swing.JFrame;

public class Test456 extends JFrame{

public static void main(String[] str){

//重写了JFrame中的paint()方法(该方法实际从JComponent中继承)。

JFrame frame = new JFrame("Frame"){

public void paint(Graphics e) {

e.drawString("画一条直线、矩形", 30, 60);

e.drawLine(30, 90, 100, 90);

e.drawRect(30, 120, 100, 50);

}

};

frame.setSize(600, 400);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

}

用JAVA显示图形

将图片0~图片9的路径(或是URL)按顺序存放在数组中。将输入映射为数组索引,找到对应的图片路径,加载和显示这幅图片。

在窗体中,java显示图片怎么做

下面是一个JAVA显示图片的例子,请参考:

package com.tarena.java;

import t.Image;

import .File;

import .IOException;

import ageio.ImageIO;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.SwingUtilities;

/**

* 加载显示图象,需要JDK1.5或以上

*/

public class showtu extends JFrame {

public showtu(String bmpFile) {

Image image = null;

try {

image = ad(new File(bmpFile));

} catch (IOException ex) {

}

JLabel label = new JLabel(new ImageIcon(image));

add(label);

setDefaultCloseOperation(EXIT_ON_CLOSE);

pack();

}

public static void main(String[] args){

final String fileName = "F:\\456备用\\亮个相.JPG"; //换成你要显示的图片

vokeLater(new Runnable(){

public void run(){

new showtu(fileName).setVisible(true);

}

});

}

}

java中怎样在界面中显示图片

方法一:

[java] view plain copy

JLabel helloLabel = new JLabel("New label");

helloLabel.setIcon(new ImageIcon("E:\\javaSE\u4EE3\u7801\\TimeManager\\asset\\hello.gif"));

helloLabel.setBackground(Color.BLACK);

helloLabel.setBounds(0, 0, 105, 50);

contentPane.add(helloLabel);

方法二:

[java] view plain copy

ImageIcon imagetoshow=new ImageIcon(urlofimagetoshow);

JLabel showimagelabel=new JLabel(imagetoshow);

this.getLayeredPane().add(showimagelabel,

new Integer(Integer.MIN_VALUE)); // 设置JLabel在最底层

showimagelabel.setBounds(0, 0, 500,150);

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

The End

发布于:2022-11-30,除非注明,否则均为首码项目网原创文章,转载请注明出处。