宝马320i拆仪表台教程:java问题!!!!!!!!

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 03:24:19
没有错误显示

我想点击按钮 显示图片,下面的程序如何调整??
package lolo;

import javax.swing.*;
import java.io.*;
import java.awt.image.*;
import java.awt.event.*;
import java.awt.*;
public class ltj extends JFrame implements ActionListener
{
Image image;
int new_w;
int new_h;
JButton hh = new JButton();
public ltj()
{
super("美丽图片");
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
show();
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args)
{
ltj ltj1 = new ltj();
}
private void jbInit() throws Exception {
hh.setBounds(new Rectangle(165, 225, 91, 37));
hh.setText("显示图片");
this.getContentPane().setLayout(null);
setSize(new Dimension(443, 326));
hh.addActionListener(this);

this.getContentPane().add(hh, null);

}
public void actionPerformed(ActionEvent e)
{
try
{
File file = new File("G:/68.jpg");
image = javax.imageio.ImageIO.read(file);
int width=image.getWidth(null);
int height=image.getHeight(null);

float tagsize=200;
float tempdouble;

if(width>height)
tempdouble=width/tagsize;
else
tempdouble=height/tagsize;

new_w=Math.round(width/tempdouble);
new_h=Math.round(height/tempdouble);

JLabel panel = new JLabel() {

protected void paintComponent(Graphics g) {
super.paintComponent(g);

g.drawImage(image,50,50,new_w,new_h,this);

}
};
this.getContentPane().add(panel,null);
this.getContentPane().validate();

// BufferedImage tag = new BufferedImage(new_w,new_h,BufferedImage.TYPE_INT_RGB);
// tag.getGraphics().drawImage(image,0,0,new_w,new_h,null);
}
catch(FileNotFoundException fnfe)
{
System.out.println(fnfe);
}
catch(IOException ioe)
{
System.out.println(ioe);
}

}
}

www.beyond.name