我的这个Java程序怎么修改,按钮才有选择图片的功能
importjava.awt.*;importjava.net.URL;importjavax.swing.*;publicclasslianxi1extendsJFra...
import java.awt.*;
import java.net.URL;
import javax.swing.*;
public class lianxi1 extends JFrame{
Image img;
JButton jbutton;
public lianxi1(){
URL imgUrl=URL.class.getResource("/img1.jpg");
img=Toolkit.getDefaultToolkit().getImage(imgUrl);
jbutton=new JButton("旋转") ;
this.setSize(500,500);
this.setTitle("绘图图片");
this.add(new lianxi());
}
public static void main(String[] args) {
new lianxi1().setVisible(true);}
class lianxi extends Canvas{
public void paint(Graphics g){
super.paint(g);
Graphics2D g2=(Graphics2D)g;
g2.drawImage(img,0,0,this);
g2.rotate(60);
}
}
} 展开
import java.net.URL;
import javax.swing.*;
public class lianxi1 extends JFrame{
Image img;
JButton jbutton;
public lianxi1(){
URL imgUrl=URL.class.getResource("/img1.jpg");
img=Toolkit.getDefaultToolkit().getImage(imgUrl);
jbutton=new JButton("旋转") ;
this.setSize(500,500);
this.setTitle("绘图图片");
this.add(new lianxi());
}
public static void main(String[] args) {
new lianxi1().setVisible(true);}
class lianxi extends Canvas{
public void paint(Graphics g){
super.paint(g);
Graphics2D g2=(Graphics2D)g;
g2.drawImage(img,0,0,this);
g2.rotate(60);
}
}
} 展开
1个回答
展开全部
图片运用:
URL url=test6.class.getResource("Icom/test.png");
Icon icon=new ImageIcon(url);
label.setIcon(icon);
or
ClassLoader cl=this.getClass().getClassLoader();
label.setIcon(new ImageIcon(cl.getResource("Icom/test.png")));
URL url=test6.class.getResource("Icom/test.png");
Icon icon=new ImageIcon(url);
label.setIcon(icon);
or
ClassLoader cl=this.getClass().getClassLoader();
label.setIcon(new ImageIcon(cl.getResource("Icom/test.png")));
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询